home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / MacApp / MacApp 2.0 CD Release / MacApp 2.0 (Many Libraries) / Libraries / UDialog.inc1.p < prev    next >
Encoding:
Text File  |  1990-03-27  |  92.4 KB  |  3,683 lines  |  [TEXT/MPS ]

  1. {$P}
  2. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  3. { UDDialog.inc1.p }
  4. { Copyright © 1988-1990 Apple Computer Inc. All rights reserved. }
  5.  
  6. {--------------------------------------------------------------------------------------------------}
  7. {$S DlgInit}
  8.  
  9. PROCEDURE InitUDialog;
  10.  
  11.     BEGIN
  12.     IF qTemplateViews THEN
  13.         BEGIN
  14.         { So the linker doesn't dead strip these }
  15.         IF gDeadStripSuppression THEN
  16.             BEGIN
  17.             IF Member(TObject(NIL), TDialogView) THEN;
  18.             IF Member(TObject(NIL), TControl) THEN;
  19.             IF Member(TObject(NIL), TButton) THEN;
  20.             IF Member(TObject(NIL), TCheckBox) THEN;
  21.             IF Member(TObject(NIL), TRadio) THEN;
  22.             IF Member(TObject(NIL), TCluster) THEN;
  23.             IF Member(TObject(NIL), TIcon) THEN;
  24.             IF Member(TObject(NIL), TPicture) THEN;
  25.             IF Member(TObject(NIL), TPopup) THEN;
  26.             IF Member(TObject(NIL), TStaticText) THEN;
  27.             IF Member(TObject(NIL), TEditText) THEN;
  28.             IF Member(TObject(NIL), TNumberText) THEN;
  29.             IF Member(TObject(NIL), TPattern) THEN;
  30.             END;
  31.  
  32.         RegisterStdType('TDialogView', kStdDialogView);
  33.         RegisterStdType('TControl', kStdControl);
  34.         RegisterStdType('TButton', kStdButton);
  35.         RegisterStdType('TCheckBox', kStdCheckBox);
  36.         RegisterStdType('TRadio', kStdRadio);
  37.         RegisterStdType('TCluster', kStdCluster);
  38.         RegisterStdType('TIcon', kStdIcon);
  39.         RegisterStdType('TPicture', kStdPicture);
  40.         RegisterStdType('TPopup', kStdPopup);
  41.         RegisterStdType('TStaticText', kStdStaticText);
  42.         RegisterStdType('TEditText', kStdEditText);
  43.         RegisterStdType('TNumberText', kStdNumberText);
  44.         RegisterStdType('TPattern', kStdPattern);
  45.         END;
  46.  
  47.     gUDialogInitialized := TRUE;
  48.     END;
  49.  
  50. {--------------------------------------------------------------------------------------------------}
  51. {$S DlgRes}
  52.  
  53. PROCEDURE GetMenuColors(popupRect: Rect;
  54.                         menuID, itemNum: INTEGER;
  55.                         VAR fColor, bColor: RGBColor);
  56.  
  57.     VAR
  58.         gotTitle:            BOOLEAN;
  59.         gdh:                GDHandle;
  60.         mce:                MCEntryPtr;
  61.         titleMce:            MCEntry;
  62.         globalMce:            MCEntry;
  63.  
  64.     PROCEDURE SetBadColors;
  65.  
  66.         BEGIN
  67.         fColor := gRGBBlack;
  68.         bColor := gRGBWhite;
  69.         END;
  70.  
  71.     BEGIN
  72.     gotTitle := False;                                    { Assume the worst. We always do. }
  73.  
  74.     IF EmptyRect(popupRect) THEN
  75.         SetBadColors                                    { Can't see it anyway so use B&W }
  76.     ELSE IF qNeedsColorQD | gConfiguration.hasColorQD THEN { First, be sure we have color QD… }
  77.         BEGIN
  78.         LocalToGlobal(popupRect.topLeft);                { Globalize rect, in focused coordinates }
  79.         LocalToGlobal(popupRect.botRight);
  80.         gdh := GetMaxDevice(popupRect);                 { Get device characteristics for that rect }
  81.  
  82.         IF (gdh <> NIL) & (gdh^^.gdPMap^^.pixelSize > 1) THEN { If we have more than two colors }
  83.             BEGIN
  84.             mce := GetMCEntry(menuID, 0);                { Always get title entry }
  85.             IF mce <> NIL THEN
  86.                 BEGIN
  87.                 gotTitle := TRUE;
  88.                 titleMce := mce^;                        { Future calls could shift memory }
  89.                 END;
  90.  
  91.             IF NOT gotTitle THEN                        { If we can't get the title entry, then… }
  92.                 BEGIN
  93.                 mce := GetMCEntry(0, 0);                { …we'll need the global entry, too }
  94.                 IF mce <> NIL THEN
  95.                     globalMce := mce^
  96.                 ELSE
  97.                     BEGIN
  98.                     SetBadColors;                        { If no title, AND no global entry, punt }
  99.                     EXIT(GetMenuColors);                { Even if item guy exists. No title, No
  100.                                                          washee }
  101.                     END;
  102.                 END;
  103.  
  104.             { Handle a title color request }
  105.             IF itemNum = 0 THEN
  106.                 BEGIN
  107.                 IF gotTitle THEN
  108.                     BEGIN
  109.                     fColor := titleMce.mctRGB1;
  110.                     bColor := titleMce.mctRGB2;
  111.                     END
  112.                 ELSE                                    { IF gotGlobal << has to be, by this point }
  113.                     BEGIN
  114.                     fColor := globalMce.mctRGB1;
  115.                     bColor := globalMce.mctRGB4;
  116.                     END;
  117.                 END
  118.                 { Otherwise, it's for an item }
  119.             ELSE
  120.                 BEGIN
  121.                 mce := GetMCEntry(menuID, itemNum);
  122.                 IF mce <> NIL THEN
  123.                     fColor := mce^.mctRGB2
  124.                 ELSE IF gotTitle THEN
  125.                     fColor := titleMce.mctRGB3
  126.                 ELSE
  127.                     fColor := globalMce.mctRGB3;
  128.  
  129.                 IF gotTitle THEN
  130.                     bColor := titleMce.mctRGB4
  131.                 ELSE
  132.                     bColor := globalMce.mctRGB2;
  133.                 END;
  134.             END
  135.         ELSE
  136.             SetBadColors;                                { Only one bit depth. Default to B&W }
  137.         END
  138.     ELSE
  139.         SetBadColors;                                    { Not using Color QuickDraw. B&W for sure }
  140.  
  141.     {$IFC qDebug}
  142.     IF gIntenseDebugging THEN
  143.         BEGIN
  144.         IF itemNum = 0 THEN
  145.             WRITE('Title ')
  146.         ELSE
  147.             WRITE('Item #', itemNum: 0);
  148.         WRITELN(' foreground color- R:', fColor.red: 0, ', G:', fColor.green: 0, ', B:',
  149.                 fColor.blue: 0);
  150.         IF itemNum = 0 THEN
  151.             WRITE('Title ')
  152.         ELSE
  153.             WRITE('Item #', itemNum: 0);
  154.         WRITELN(' background color- R:', bColor.red: 0, ', G:', bColor.green: 0, ', B:',
  155.                 bColor.blue: 0);
  156.         END;
  157.     {$ENDC}
  158.     END;
  159.  
  160. {--------------------------------------------------------------------------------------------------}
  161. {$S DlgOpen}
  162.  
  163. PROCEDURE TDialogView.IDialogView(itsDocument: TDocument;
  164.                                   itsSuperView: TView;
  165.                                   itsLocation, itsSize: VPoint;
  166.                                   itsHSizeDet, itsVSizeDet: SizeDeterminer;
  167.                                   itsDefItemID, itsCancelItemID: IDType);
  168.  
  169.     VAR
  170.         anAssociation:        TAssociation;
  171.         fi:                 FailInfo;
  172.  
  173.     PROCEDURE HandleFailure(error: OSErr;
  174.                             message: LONGINT);
  175.  
  176.         BEGIN
  177.         Free;
  178.         END;
  179.  
  180.     BEGIN
  181.     {$IFC qDebug}
  182.     IF NOT gUDialogInitialized THEN
  183.         BEGIN
  184.         ProgramBreak('InitUDialog must be called before creating a Dialog View.');
  185.         Failure(noErr, 0);
  186.         END;
  187.     {$ENDC}
  188.  
  189.     fParamTxt := NIL;                                    { In case of a catastrophe }
  190.     fTEView := NIL;                                     { Ditto. }
  191.     IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  192.  
  193.     CatchFailures(fi, HandleFailure);
  194.     New(anAssociation);                                 { Okay to allocate list now }
  195.     FailNIL(anAssociation);
  196.     anAssociation.IAssociation;
  197.     fParamTxt := anAssociation;
  198.     fDefaultItem := itsDefItemID;
  199.     fCancelItem := itsCancelItemID;
  200.     fCurrentEditText := NIL;
  201.     fDismissed := False;
  202.     fDismisser := kNoIdentifier;
  203.  
  204.     fTEView := MakeTEView;
  205.     Success(fi);
  206.     END;
  207.  
  208. {--------------------------------------------------------------------------------------------------}
  209. {$S DlgOpen}
  210.  
  211. PROCEDURE TDialogView.IRes(itsDocument: TDocument;
  212.                            itsSuperView: TView;
  213.                            VAR itsParams: Ptr); OVERRIDE;
  214.  
  215.     VAR
  216.         anAssociation:        TAssociation;
  217.         fi:                 FailInfo;
  218.  
  219.     PROCEDURE HandleFailure(error: OSErr;
  220.                             message: LONGINT);
  221.  
  222.         BEGIN
  223.         Free;
  224.         END;
  225.  
  226.     BEGIN
  227.     {$IFC qDebug}
  228.     IF NOT gUDialogInitialized THEN
  229.         BEGIN
  230.         ProgramBreak('InitUDialog must be called before creating a Dialog View.');
  231.         Failure(noErr, 0);
  232.         END;
  233.     {$ENDC}
  234.  
  235.     fParamTxt := NIL;                                    { In case of a catastrophe }
  236.     fTEView := NIL;                                     { Ditto. }
  237.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  238.     WITH DialogViewTemplatePtr(itsParams)^ DO
  239.         BEGIN
  240.         fDefaultItem := defaultItem;
  241.         fCancelItem := cancelItem;
  242.         END;
  243.     CatchFailures(fi, HandleFailure);
  244.     New(anAssociation);                                 { Okay to allocate list now }
  245.     FailNIL(anAssociation);
  246.     anAssociation.IAssociation;
  247.     fParamTxt := anAssociation;
  248.     fCurrentEditText := NIL;
  249.     fDismissed := False;
  250.     fDismisser := kNoIdentifier;
  251.  
  252.     fTEView := MakeTEView;
  253.     Success(fi);
  254.  
  255.     OffsetPtr(itsParams, SIZEOF(DialogViewTemplate));
  256.     END;
  257.  
  258. {--------------------------------------------------------------------------------------------------}
  259. {$S MAWriteRes}
  260.  
  261. PROCEDURE TDialogView.WRes(theResource: ViewRsrcHndl;
  262.                            VAR itsParams: Ptr); OVERRIDE;
  263.  
  264.     VAR
  265.         dgPtr:                DialogViewTemplatePtr;
  266.  
  267.     BEGIN
  268.     INHERITED WRes(theResource, itsParams);
  269.  
  270.     dgPtr := DialogViewTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(DialogViewTemplate)));
  271.  
  272.     WITH dgPtr^ DO
  273.         BEGIN
  274.         defaultItem := fDefaultItem;
  275.         cancelItem := fCancelItem;
  276.         END;
  277.     END;
  278.  
  279. {--------------------------------------------------------------------------------------------------}
  280. {$S MAWriteRes}
  281.  
  282. PROCEDURE TDialogView.WriteRes(theResource: ViewRsrcHndl;
  283.                                VAR itsParams: Ptr); OVERRIDE;
  284.  
  285.     BEGIN
  286.     gWResSignature := 'dlog'; gWResType := 'TDialogView';
  287.     WRes(theResource, itsParams);
  288.     END;
  289.  
  290. {--------------------------------------------------------------------------------------------------}
  291. {$S DlgClose}
  292.  
  293. PROCEDURE TDialogView.Free; OVERRIDE;
  294.  
  295.     VAR
  296.         itsTEView:            TDialogTEView;
  297.  
  298.     BEGIN
  299.     FreeIfObject(fParamTxt);
  300.     fParamTxt := NIL;
  301.  
  302.     { We postpone freeing fTEView because we don't know if it's still associated with an
  303.       edittext view.  (At this point it normally wouldn't be associated with an edittext,
  304.       but you never know…  So, free it after we've free'd all our subviews, including
  305.       any edittext view that fTEView might be associated with. We also disassociated from
  306.       its superview, if any, to avoid having free'd for us by INHERITED Free. }
  307.  
  308.     itsTEView := fTEView;                                { Can't refer to fTEView after calling
  309.                                                          INHERITED Free }
  310.     fTEView := NIL;
  311.  
  312.     IF (itsTEView <> NIL) & (itsTEView.fSuperView <> NIL) THEN
  313.         itsTEView.fSuperView.RemoveSubView(itsTEView);
  314.  
  315.     INHERITED Free;
  316.  
  317.     FreeIfObject(itsTEView);                            { Now free this puppy }
  318.     itsTEView := NIL;
  319.     END;
  320.  
  321. {--------------------------------------------------------------------------------------------------}
  322. {$S DlgRes}
  323.  
  324. FUNCTION TDialogView.CanDismiss(dismissing: IDType): BOOLEAN;
  325.  
  326.     VAR
  327.         dismissingView:     TView;
  328.         successful:         BOOLEAN;
  329.  
  330.     BEGIN
  331.     { First, make sure the view initiating the the dismissal, if any, is enabled. }
  332.  
  333.     IF LONGINT(dismissing) <> LONGINT(kNoIdentifier) THEN
  334.         dismissingView := FindSubView(dismissing)
  335.     ELSE
  336.         dismissingView := NIL;                            { no dismissing view }
  337.  
  338.     { Thanks Tommi GESSL }
  339.     successful := (dismissingView = NIL) | (dismissingView.IsViewEnabled);
  340.     CanDismiss := successful;
  341.  
  342.     IF successful THEN                                    { test only we haven´t failed }
  343.         { Now, if we're not cancelling, make sure the current edit text is valid and
  344.         return false if it isn't.}
  345.  
  346.         IF (LONGINT(fCancelItem) = LONGINT(kNoIdentifier)) | (dismissing <> fCancelItem) THEN
  347.             BEGIN
  348.             DoSelectEditText(NIL, False);                { Attempt to deselect current edit text }
  349.             CanDismiss := fCurrentEditText = NIL;        { Successful only if it was deselected }
  350.             END;
  351.     END;
  352.  
  353. {--------------------------------------------------------------------------------------------------}
  354. {$S DlgNonRes}
  355.  
  356. PROCEDURE TDialogView.CantDeselect(theEditText: TEditText;
  357.                                    reason: LONGINT);
  358.  
  359.     VAR
  360.         aString:            Str255;
  361.  
  362.     BEGIN
  363.     IF reason <> kValidValue THEN
  364.         BEGIN
  365.         IF reason <> kErrorHandled THEN                 { go ahead and post an alert }
  366.             BEGIN
  367.             IF (reason < 1) | (reason > kNoOfDefaultReasons) THEN
  368.                 reason := kInvalidValue;
  369.  
  370.             GetIndString(aString, kInvalidValueReasons, reason);
  371.             ParamText(aString, '', '', '');
  372.             StdAlert(phInvalidValue);
  373.             END;
  374.         aString := theEditText.fDataHandle^^;            { Restart with previous value }
  375.         theEditText.RestartEdit(aString);
  376.         END;
  377.     END;
  378.  
  379. {--------------------------------------------------------------------------------------------------}
  380. {$S DlgClose}
  381.  
  382. PROCEDURE TDialogView.Close; OVERRIDE;
  383.  
  384.     BEGIN
  385.     IF LONGINT(fDismisser) = LONGINT(kNoIdentifier) THEN
  386.         DismissDialog(kNoIdentifier);
  387.  
  388.     INHERITED Close;
  389.     END;
  390.  
  391. {--------------------------------------------------------------------------------------------------}
  392. {$S DlgRes}
  393.  
  394. FUNCTION TDialogView.DeselectCurrentEditText: BOOLEAN;
  395.  
  396.     VAR
  397.         validateResult:     LONGINT;
  398.         itsWindow:            TWindow;
  399.         lastCommand:        TCommand;
  400.  
  401.     BEGIN
  402.     DeselectCurrentEditText := TRUE;
  403.  
  404.     IF fCurrentEditText <> NIL THEN
  405.         BEGIN
  406.         { Commit the last command to prevent undo from applying to the wrong edit text,
  407.           and to ensure that all changes are made before validating. }
  408.         IF (fTEView <> NIL) THEN
  409.             BEGIN
  410.             lastCommand := fTEView.GetLastCommand;
  411.             IF (lastCommand <> NIL) & (lastCommand.fView = fTEView) THEN
  412.                 fTEView.CommitLastCommand;
  413.             END;
  414.  
  415.         validateResult := fCurrentEditText.Validate;
  416.         IF validateResult = kValidValue THEN
  417.             BEGIN
  418.             fCurrentEditText.StopEdit;
  419.             fCurrentEditText := NIL;                    { No edit text is selected }
  420.             itsWindow := GetWindow;                     { Patch up the target change }
  421.             IF itsWindow <> NIL THEN
  422.                 itsWindow.SetTarget(SELF)
  423.             ELSE
  424.                 gApplication.SetTarget(gApplication);
  425.             END
  426.         ELSE
  427.             BEGIN
  428.             CantDeselect(fCurrentEditText, validateResult);
  429.             DeselectCurrentEditText := False;
  430.             END;
  431.         END;
  432.     END;
  433.  
  434. {--------------------------------------------------------------------------------------------------}
  435. {$S DlgClose}
  436.  
  437. PROCEDURE TDialogView.DismissDialog(dismisser: IDType);
  438.  
  439.     VAR
  440.         dismissingControl:    TControl;
  441.  
  442.     BEGIN
  443.     IF NOT fDismissed THEN
  444.         IF CanDismiss(dismisser) THEN
  445.             BEGIN
  446.             fDismissed := TRUE;
  447.             fDismisser := dismisser;
  448.             END
  449.         ELSE
  450.             Failure(noErr, 0);                            { Silent failure }
  451.     END;
  452.  
  453. {--------------------------------------------------------------------------------------------------}
  454. {$S DlgRes}
  455.  
  456. PROCEDURE TDialogView.DoChoice(origView: TView;
  457.                                itsChoice: INTEGER); OVERRIDE;
  458.  
  459.     BEGIN
  460.     CASE itsChoice OF
  461.         mEditTextHit:
  462.             BEGIN
  463.             {$IFC qDebug}
  464.             IF NOT Member(origView, TEditText) THEN
  465.                 ProgramBreak('Got mEditTextHit on non-TEditText view.')
  466.             ELSE
  467.             {$ENDC}
  468.                 DoSelectEditText(TEditText(origView), False);
  469.             END;
  470.         OTHERWISE
  471.             IF Member(origView, TControl) & TControl(origView).fDismissesDialog THEN
  472.                 DismissDialog(origView.fIdentifier)
  473.             ELSE
  474.                 INHERITED DoChoice(origView, itsChoice);
  475.     END;
  476.     END;
  477.  
  478. {--------------------------------------------------------------------------------------------------}
  479. {$S DlgRes}
  480.  
  481. FUNCTION TDialogView.DoCommandKey(ch: CHAR;
  482.                                   VAR info: EventInfo): TCommand; OVERRIDE;
  483.  
  484.     VAR
  485.         cancelView:         TView;
  486.  
  487.     BEGIN
  488.     IF IsViewEnabled & (ch = '.') & (LONGINT(fCancelItem) <> LONGINT(kNoIdentifier)) THEN
  489.         BEGIN
  490.         cancelView := FindSubView(fCancelItem);
  491.         IF (cancelView <> NIL) & Member(cancelView, TControl) THEN
  492.             BEGIN
  493.             IF cancelView.IsViewEnabled THEN
  494.                 TControl(cancelView).Flash;
  495.             TControl(cancelView).DoChoice(cancelView, TControl(cancelView).fDefChoice);
  496.             END
  497.         ELSE
  498.             DoChoice(cancelView, mCancelKey);
  499.         DoCommandKey := NIL;
  500.         END
  501.     ELSE
  502.         DoCommandKey := INHERITED DoCommandKey(ch, info);
  503.     END;
  504.  
  505. {--------------------------------------------------------------------------------------------------}
  506. {$S DlgRes}
  507.  
  508. FUNCTION TDialogView.DoKeyCommand(ch: CHAR;
  509.                                   aKeyCode: INTEGER;
  510.                                   VAR info: EventInfo): TCommand; OVERRIDE;
  511.  
  512.     VAR
  513.         defaultView:        TView;
  514.         cancelView:         TView;
  515.  
  516.     BEGIN
  517.     { If we get this far, nobody's handled the Tab, Enter, or Return keys, so we will  }
  518.     DoKeyCommand := NIL;
  519.     IF IsViewEnabled THEN
  520.         CASE ch OF
  521.             chEscape:
  522.                 IF aKeyCode = kClearVirtualCode THEN    { esc double for two different keys! }
  523.                     DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info)
  524.                 ELSE IF LONGINT(fCancelItem) <> LONGINT(kNoIdentifier) THEN
  525.                     BEGIN
  526.                     cancelView := FindSubView(fCancelItem);
  527.                     IF (cancelView <> NIL) & Member(cancelView, TControl) THEN
  528.                         BEGIN
  529.                         IF cancelView.IsViewEnabled THEN
  530.                             TControl(cancelView).Flash;
  531.                         TControl(cancelView).DoChoice(cancelView, TControl(cancelView).fDefChoice);
  532.                         END
  533.                     ELSE
  534.                         DoChoice(cancelView, mCancelKey);
  535.                     END
  536.                 ELSE
  537.                     DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  538.             chTab:
  539.                 Tab(info.theShiftKey);
  540.             chEnter, chReturn:
  541.                 IF LONGINT(fDefaultItem) <> LONGINT(kNoIdentifier) THEN
  542.                     BEGIN
  543.                     defaultView := FindSubView(fDefaultItem);
  544.                     IF (defaultView <> NIL) & Member(defaultView, TControl) THEN
  545.                         BEGIN
  546.                         IF defaultView.IsViewEnabled THEN
  547.                             TControl(defaultView).Flash;
  548.                         TControl(defaultView).DoChoice(defaultView, TControl(defaultView).fDefChoice);
  549.                         END
  550.                     ELSE
  551.                         DoChoice(defaultView, mDefaultKey);
  552.                     END
  553.                 ELSE
  554.                     DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  555.             OTHERWISE
  556.                 DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  557.         END
  558.     ELSE
  559.         DoKeyCommand := INHERITED DoKeyCommand(ch, aKeyCode, info);
  560.     END;
  561.  
  562. {--------------------------------------------------------------------------------------------------}
  563. {$S DlgRes}
  564.  
  565. PROCEDURE TDialogView.DoSelectEditText(theEditText: TEditText;
  566.                                        selectChars: BOOLEAN);
  567.  
  568.     VAR
  569.         itsWindow:            TWindow;
  570.  
  571.     BEGIN
  572.     IF theEditText <> fCurrentEditText THEN             { If we're not editing this view… }
  573.         BEGIN
  574.         IF DeselectCurrentEditText THEN
  575.             BEGIN
  576.             fCurrentEditText := theEditText;
  577.             IF theEditText <> NIL THEN
  578.                 BEGIN
  579.                 IF theEditText.fViewEnabled THEN
  580.                     theEditText.StartEdit(selectChars, fTEView)
  581.                     {$IFC qDebug}
  582.                 ELSE
  583.                     ProgramBreak('Attempt to select a disabled edit text view')
  584.                     {$ENDC}
  585.                                  ;
  586.                 END
  587.             ELSE
  588.                 BEGIN
  589.                 itsWindow := GetWindow;                 { Set the window's target to self }
  590.                 IF itsWindow <> NIL THEN
  591.                     itsWindow.SetTarget(SELF);
  592.                 END;
  593.             END;
  594.         END
  595.     ELSE IF selectChars & (theEditText <> NIL) THEN     { Make sure all the chars are selected. }
  596.         theEditText.SetSelection(0, MAXINT, kRedraw);
  597.     END;
  598.  
  599. {--------------------------------------------------------------------------------------------------}
  600. {$S DlgRes}
  601.  
  602. PROCEDURE TDialogView.EachEditText(PROCEDURE DoToEditText(theEditText: TEditText));
  603.  
  604.     PROCEDURE CheckSubView(theSubView: TView);
  605.  
  606.         BEGIN
  607.         IF Member(theSubView, TEditText) THEN
  608.             DoToEditText(TEditText(theSubView))
  609.         ELSE
  610.             theSubView.EachSubView(CheckSubView);
  611.         END;
  612.  
  613.     BEGIN
  614.     EachSubView(CheckSubView);
  615.     END;
  616.  
  617. {--------------------------------------------------------------------------------------------------}
  618. {$S DlgRes}
  619.  
  620. FUNCTION TDialogView.GetDialogView: TView; OVERRIDE;
  621.  
  622.     BEGIN
  623.     GetDialogView := SELF;
  624.     END;
  625.  
  626. {--------------------------------------------------------------------------------------------------}
  627. {$S DlgRes}
  628.  
  629. PROCEDURE TDialogView.Tab(tabBackward: BOOLEAN);
  630.  
  631.     VAR
  632.         first:                TEditText;
  633.         last:                TEditText;
  634.         next:                TEditText;
  635.         previous:            TEditText;
  636.  
  637.     BEGIN
  638.     SurveyEditText(first, last, next, previous);
  639.  
  640.     IF tabBackward THEN
  641.         next := previous;
  642.  
  643.     IF next <> NIL THEN
  644.         DoSelectEditText(next, TRUE);
  645.     END;
  646.  
  647. {--------------------------------------------------------------------------------------------------}
  648. {$S DlgOpen}
  649.  
  650. FUNCTION TDialogView.MakeTEView: TDialogTEView;
  651.  
  652.     VAR
  653.         aDialogTEView:        TDialogTEView;
  654.  
  655.     BEGIN
  656.     New(aDialogTEView);
  657.     FailNIL(aDialogTEView);
  658.     aDialogTEView.IDialogTEView(NIL, NIL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable,
  659.                                 gZeroRect, gSystemStyle, teJustSystem, kWithoutStyle, False);
  660.  
  661.     aDialogTEView.fMinAhead := 1;    { Don't _jump_ the view ahead when autoscrolling for
  662.     scrollselectionintoview }
  663.  
  664.     MakeTEView := aDialogTEView;
  665.     END;
  666.  
  667. {--------------------------------------------------------------------------------------------------}
  668. {$S MAOpen}
  669.  
  670. PROCEDURE TDialogView.DoOpen;
  671.  
  672.     VAR
  673.         itsWindow:            TWindow;
  674.  
  675.     BEGIN
  676.     itsWindow := GetWindow;
  677.     IF (itsWindow <> NIL) & Member(itsWindow.fTarget, TEditText) THEN
  678.         { If the window's target is an edit text view, and that edit text view is installed
  679.           in this dialog, then select it.  Note that this can be problematic if the edit
  680.           text view is in nested dialog views. }
  681.         WITH itsWindow DO
  682.             IF FindSubView(TEditText(fTarget).fIdentifier) = fTarget THEN
  683.                 DoSelectEditText(TEditText(fTarget), TRUE);
  684.     END;
  685.  
  686. {--------------------------------------------------------------------------------------------------}
  687. {$S MAOpen}
  688.  
  689. PROCEDURE TDialogView.Open; OVERRIDE;
  690.  
  691.     BEGIN
  692.     fDismissed := False;
  693.     fDismisser := kNoIdentifier;
  694.     DoOpen;
  695.     INHERITED Open;
  696.     END;
  697.  
  698. {--------------------------------------------------------------------------------------------------}
  699. {$S DlgRes}
  700.  
  701. PROCEDURE TDialogView.ParamTxt(keyStr, valueStr: Str255);
  702.  
  703.     BEGIN
  704.     fParamTxt.InsertEntry(keyStr, valueStr);
  705.     END;
  706.  
  707. {--------------------------------------------------------------------------------------------------}
  708. {$S DlgRes}
  709.  
  710. FUNCTION TDialogView.PoseModally: IDType;
  711.  
  712.     LABEL 1;
  713.  
  714.     VAR
  715.         itsWindow:            TWindow;
  716.         fi:                 FailInfo;
  717.  
  718.     PROCEDURE HdlPoseModally(error: OSErr;
  719.                              message: LONGINT);
  720.  
  721.         BEGIN
  722.         IF error = noErr THEN
  723.             GOTO 1                                        { If no error then keep the dialog running }
  724.         ELSE
  725.             BEGIN
  726.             fDismissed := TRUE;                         { Avoid validating selected edit text }
  727.             itsWindow.Close;                            { If an error then close the dialog and exit
  728.                                                          via failure mechanism }
  729.             END;
  730.         END;
  731.  
  732.     BEGIN
  733.     itsWindow := GetWindow;
  734.     IF itsWindow <> NIL THEN
  735.         BEGIN
  736.         gApplication.CommitLastCommand;                 { Make sure that the undo menu reflects }
  737.         { the view being looked at.  Otherwise }
  738.         { the undo menu will be wrong.        }
  739.  
  740.         itsWindow.Open;
  741.         itsWindow.Select;                                { Bring it to the front }
  742.  
  743.         fDismissed := False;
  744.         REPEAT
  745.             CatchFailures(fi, HdlPoseModally);
  746.             gApplication.PollEvent(kAllowApplicationToSleep);
  747.             Success(fi);
  748.         1:
  749.         UNTIL fDismissed;
  750.         PoseModally := fDismisser;
  751.  
  752.         END
  753.     ELSE
  754.         PoseModally := kNoIdentifier;
  755.     END;
  756.  
  757. {--------------------------------------------------------------------------------------------------}
  758. {$S DlgRes}
  759.  
  760. PROCEDURE TDialogView.ReplaceText(VAR theText: Str255);
  761.  
  762.     PROCEDURE ReplaceOnce(item: TEntry);
  763.  
  764.         VAR
  765.             index:                INTEGER;
  766.  
  767.         BEGIN
  768.         WITH item DO
  769.             REPEAT
  770.                 index := Pos(fKey^^, theText);
  771.                 IF index > 0 THEN
  772.                     BEGIN
  773.                     Delete(theText, index, Length(fKey^^));
  774.                     IF Length(theText) + Length(fValue^^) < SIZEOF(Str255) THEN
  775.                         Insert(fValue^^, theText, index);
  776.                     END;
  777.             UNTIL index = 0;
  778.         END;
  779.  
  780.     BEGIN
  781.     fParamTxt.fEntries.Each(ReplaceOnce);
  782.     END;
  783.  
  784. {--------------------------------------------------------------------------------------------------}
  785. {$S DlgRes}
  786.  
  787. PROCEDURE TDialogView.SelectEditText(itsIdentifier: IDType;
  788.                                      selectChars: BOOLEAN);
  789.  
  790.     VAR
  791.         aSubView:            TView;
  792.  
  793.     BEGIN
  794.     aSubView := FindSubView(itsIdentifier);
  795.     IF (aSubView <> NIL) & (Member(aSubView, TEditText)) THEN
  796.         DoSelectEditText(TEditText(aSubView), selectChars);
  797.     END;
  798.  
  799. {--------------------------------------------------------------------------------------------------}
  800. {$S DlgRes}
  801.  
  802. PROCEDURE TDialogView.SurveyEditText(VAR first, last, next, previous: TEditText);
  803.  
  804.     VAR
  805.         foundCurrent:        BOOLEAN;
  806.  
  807.     PROCEDURE Survey(theEditText: TEditText);
  808.  
  809.         BEGIN
  810.         IF theEditText.fViewEnabled & theEditText.fShown THEN
  811.             BEGIN
  812.             IF first = NIL THEN
  813.                 first := theEditText;
  814.             last := theEditText;
  815.             IF theEditText = fCurrentEditText THEN
  816.                 foundCurrent := TRUE
  817.             ELSE IF foundCurrent & (next = NIL) THEN
  818.                 next := theEditText;
  819.             IF NOT foundCurrent THEN
  820.                 previous := theEditText;
  821.             END;
  822.         END;
  823.  
  824.     BEGIN
  825.     foundCurrent := False;
  826.     next := NIL;
  827.     previous := NIL;
  828.     first := NIL;
  829.     last := NIL;
  830.     EachEditText(Survey);
  831.     IF next = NIL THEN
  832.         next := first;
  833.     IF previous = NIL THEN
  834.         previous := last;
  835.     END;
  836.  
  837. {--------------------------------------------------------------------------------------------------}
  838. {$S DlgFields}
  839.  
  840. PROCEDURE TDialogView.Fields(PROCEDURE DoToField(fieldName: Str255;
  841.                                                  fieldAddr: Ptr;
  842.                                                  fieldType: INTEGER)); OVERRIDE;
  843.  
  844.     BEGIN
  845.     DoToField('TDialogView', NIL, bClass);
  846.     DoToField('fDefaultItem', @fDefaultItem, bIDType);
  847.     DoToField('fCancelItem', @fCancelItem, bIDType);
  848.     DoToField('fParamTxt', @fParamTxt, bObject);
  849.     DoToField('fCurrentEditText', @fCurrentEditText, bObject);
  850.     DoToField('fTEView', @fTEView, bObject);
  851.     DoToField('fDismissed', @fDismissed, bBoolean);
  852.     DoToField('fDismisser', @fDismisser, bIDType);
  853.  
  854.     INHERITED Fields(DoToField);
  855.     END;
  856.  
  857. {--------------------------------------------------------------------------------------------------}
  858. {$S DlgOpen}
  859.  
  860. PROCEDURE TButton.IButton(itsSuperView: TView;
  861.                           itsLocation, itsSize: VPoint;
  862.                           itsHSizeDet, itsVSizeDet: SizeDeterminer;
  863.                           itsLabel: Str255);
  864.  
  865.     BEGIN
  866.     ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 0,
  867.             pushButProc);
  868.     fDefChoice := mButtonHit;
  869.     END;
  870.  
  871. {--------------------------------------------------------------------------------------------------}
  872. {$S DlgOpen}
  873.  
  874. PROCEDURE TButton.IRes(itsDocument: TDocument;
  875.                        itsSuperView: TView;
  876.                        VAR itsParams: Ptr); OVERRIDE;
  877.  
  878.     VAR
  879.         itsArea:            Rect;
  880.  
  881.     BEGIN
  882.     INHERITED IRes(NIL, itsSuperView, itsParams);
  883.  
  884.     fDefChoice := mButtonHit;
  885.     ControlArea(itsArea);
  886.     WITH ButtonTemplatePtr(itsParams)^ DO
  887.         CreateCMgrControl(itsArea, itsLabel, 0, 0, 0, pushButProc);
  888.  
  889.     OffsetPtrWStr(itsParams, SIZEOF(ButtonTemplate));
  890.     END;
  891.  
  892. {--------------------------------------------------------------------------------------------------}
  893. {$S MAWriteRes}
  894.  
  895. PROCEDURE TButton.WRes(theResource: ViewRsrcHndl;
  896.                        VAR itsParams: Ptr); OVERRIDE;
  897.  
  898.     VAR
  899.         theLabel:            Str255;
  900.         btPtr:                ButtonTemplatePtr;
  901.  
  902.     BEGIN
  903.     INHERITED WRes(theResource, itsParams);
  904.  
  905.     GetText(theLabel);
  906.  
  907.     btPtr := ButtonTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(ButtonTemplate),
  908.                                              Length(theLabel)));
  909.  
  910.     { btPtr^.itsLabel := theLabel; }
  911.     CopyStr255(theLabel, PRStr(btPtr^.itsLabel));
  912.     END;
  913.  
  914. {--------------------------------------------------------------------------------------------------}
  915. {$S MAWriteRes}
  916.  
  917. PROCEDURE TButton.WriteRes(theResource: ViewRsrcHndl;
  918.                            VAR itsParams: Ptr); OVERRIDE;
  919.  
  920.     BEGIN
  921.     gWResSignature := 'butn'; gWResType := 'TButton';
  922.     WRes(theResource, itsParams);
  923.     END;
  924.  
  925. {--------------------------------------------------------------------------------------------------}
  926. {$S DlgFields}
  927.  
  928. PROCEDURE TButton.Fields(PROCEDURE DoToField(fieldName: Str255;
  929.                                              fieldAddr: Ptr;
  930.                                              fieldType: INTEGER)); OVERRIDE;
  931.  
  932.     BEGIN
  933.     DoToField('TButton', NIL, bClass);
  934.  
  935.     INHERITED Fields(DoToField);
  936.     END;
  937.  
  938. {--------------------------------------------------------------------------------------------------}
  939. {$S DlgOpen}
  940.  
  941. PROCEDURE TCheckBox.ICheckBox(itsSuperView: TView;
  942.                               itsLocation, itsSize: VPoint;
  943.                               itsHSizeDet, itsVSizeDet: SizeDeterminer;
  944.                               itsLabel: Str255;
  945.                               isTurnedOn: BOOLEAN);
  946.  
  947.     BEGIN
  948.     ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1,
  949.             checkBoxProc);
  950.     SetState(isTurnedOn, kDontRedraw);
  951.     fDefChoice := mCheckBoxHit;
  952.     END;
  953.  
  954. {--------------------------------------------------------------------------------------------------}
  955. {$S DlgOpen}
  956.  
  957. PROCEDURE TCheckBox.IRes(itsDocument: TDocument;
  958.                          itsSuperView: TView;
  959.                          VAR itsParams: Ptr); OVERRIDE;
  960.  
  961.     VAR
  962.         itsArea:            Rect;
  963.  
  964.     BEGIN
  965.     INHERITED IRes(NIL, itsSuperView, itsParams);
  966.  
  967.     fDefChoice := mCheckBoxHit;
  968.     ControlArea(itsArea);
  969.     WITH CheckBoxTemplatePtr(itsParams)^ DO
  970.         CreateCMgrControl(itsArea, itsLabel, ORD(isOn), 0, 1, checkBoxProc);
  971.  
  972.     OffsetPtrWStr(itsParams, SIZEOF(CheckBoxTemplate));
  973.     END;
  974.  
  975. {--------------------------------------------------------------------------------------------------}
  976. {$S MAWriteRes}
  977.  
  978. PROCEDURE TCheckBox.WRes(theResource: ViewRsrcHndl;
  979.                          VAR itsParams: Ptr); OVERRIDE;
  980.  
  981.     VAR
  982.         theLabel:            Str255;
  983.         cbPtr:                CheckBoxTemplatePtr;
  984.  
  985.     BEGIN
  986.     INHERITED WRes(theResource, itsParams);
  987.  
  988.     GetText(theLabel);
  989.  
  990.     cbPtr := CheckBoxTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(CheckBoxTemplate),
  991.                                                Length(theLabel)));
  992.  
  993.     cbPtr^.isOn := isOn;
  994.     { cbPtr^.itsLabel := theLabel; }
  995.     CopyStr255(theLabel, PRStr(cbPtr^.itsLabel));
  996.     END;
  997.  
  998. {--------------------------------------------------------------------------------------------------}
  999. {$S MAWriteRes}
  1000.  
  1001. PROCEDURE TCheckBox.WriteRes(theResource: ViewRsrcHndl;
  1002.                              VAR itsParams: Ptr); OVERRIDE;
  1003.  
  1004.     BEGIN
  1005.     gWResSignature := 'chkb'; gWResType := 'TCheckBox';
  1006.     WRes(theResource, itsParams);
  1007.     END;
  1008.  
  1009. {--------------------------------------------------------------------------------------------------}
  1010. {$S DlgRes}
  1011.  
  1012. PROCEDURE TCheckBox.DoChoice(origView: TView;
  1013.                              itsChoice: INTEGER);
  1014.  
  1015.     BEGIN
  1016.     IF itsChoice = mCheckBoxHit THEN
  1017.         Toggle(kRedraw);
  1018.     INHERITED DoChoice(origView, itsChoice);
  1019.     END;
  1020.  
  1021. {--------------------------------------------------------------------------------------------------}
  1022. {$S DlgRes}
  1023.  
  1024. FUNCTION TCheckBox.isOn: BOOLEAN;
  1025.  
  1026.     BEGIN
  1027.     isOn := GetLongVal <> 0;
  1028.     END;
  1029.  
  1030. {--------------------------------------------------------------------------------------------------}
  1031. {$S DlgRes}
  1032.  
  1033. PROCEDURE TCheckBox.SetState(state, redraw: BOOLEAN);
  1034.  
  1035.     BEGIN
  1036.     SetLongVal(ORD(state), redraw);
  1037.     END;
  1038.  
  1039. {--------------------------------------------------------------------------------------------------}
  1040. {$S DlgRes}
  1041.  
  1042. PROCEDURE TCheckBox.Toggle(redraw: BOOLEAN);
  1043.  
  1044.     BEGIN
  1045.     SetLongVal(ORD(NOT isOn), redraw);
  1046.     END;
  1047.  
  1048. {--------------------------------------------------------------------------------------------------}
  1049. {$S DlgRes}
  1050.  
  1051. PROCEDURE TCheckBox.ToggleIf(matchState, redraw: BOOLEAN);
  1052.  
  1053.     BEGIN
  1054.     IF isOn = matchState THEN
  1055.         SetLongVal(ORD(NOT isOn), redraw);
  1056.     END;
  1057.  
  1058. {--------------------------------------------------------------------------------------------------}
  1059. {$S DlgFields}
  1060.  
  1061. PROCEDURE TCheckBox.Fields(PROCEDURE DoToField(fieldName: Str255;
  1062.                                                fieldAddr: Ptr;
  1063.                                                fieldType: INTEGER)); OVERRIDE;
  1064.  
  1065.     BEGIN
  1066.     DoToField('TCheckBox', NIL, bClass);
  1067.  
  1068.     INHERITED Fields(DoToField);
  1069.     END;
  1070.  
  1071. {--------------------------------------------------------------------------------------------------}
  1072. {$S DlgOpen}
  1073.  
  1074. PROCEDURE TRadio.IRadio(itsSuperView: TView;
  1075.                         itsLocation, itsSize: VPoint;
  1076.                         itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1077.                         itsLabel: Str255;
  1078.                         isTurnedOn: BOOLEAN);
  1079.  
  1080.     BEGIN
  1081.     ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, 0, 0, 1,
  1082.             radioButProc);
  1083.     SetState(isTurnedOn, kDontRedraw);
  1084.     fDefChoice := mRadioHit;
  1085.     END;
  1086.  
  1087. {--------------------------------------------------------------------------------------------------}
  1088. {$S DlgOpen}
  1089.  
  1090. PROCEDURE TRadio.IRes(itsDocument: TDocument;
  1091.                       itsSuperView: TView;
  1092.                       VAR itsParams: Ptr); OVERRIDE;
  1093.  
  1094.     VAR
  1095.         itsArea:            Rect;
  1096.  
  1097.     BEGIN
  1098.     INHERITED IRes(NIL, itsSuperView, itsParams);
  1099.  
  1100.     fDefChoice := mRadioHit;
  1101.     ControlArea(itsArea);
  1102.     WITH RadioTemplatePtr(itsParams)^ DO
  1103.         CreateCMgrControl(itsArea, itsLabel, ORD(isOn), 0, 1, radioButProc);
  1104.     OffsetPtrWStr(itsParams, SIZEOF(RadioTemplate));
  1105.     END;
  1106.  
  1107. {--------------------------------------------------------------------------------------------------}
  1108. {$S MAWriteRes}
  1109.  
  1110. PROCEDURE TRadio.WRes(theResource: ViewRsrcHndl;
  1111.                       VAR itsParams: Ptr); OVERRIDE;
  1112.  
  1113.     VAR
  1114.         theLabel:            Str255;
  1115.         rdPtr:                RadioTemplatePtr;
  1116.  
  1117.     BEGIN
  1118.     INHERITED WRes(theResource, itsParams);
  1119.  
  1120.     GetText(theLabel);
  1121.  
  1122.     rdPtr := RadioTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(RadioTemplate),
  1123.                                             Length(theLabel)));
  1124.  
  1125.     rdPtr^.isOn := isOn;
  1126.     { rdPtr^.itsLabel := theLabel; }
  1127.     CopyStr255(theLabel, PRStr(rdPtr^.itsLabel));
  1128.     END;
  1129.  
  1130. {--------------------------------------------------------------------------------------------------}
  1131. {$S MAWriteRes}
  1132.  
  1133. PROCEDURE TRadio.WriteRes(theResource: ViewRsrcHndl;
  1134.                           VAR itsParams: Ptr); OVERRIDE;
  1135.  
  1136.     BEGIN
  1137.     gWResSignature := 'radb'; gWResType := 'TRadio';
  1138.     WRes(theResource, itsParams);
  1139.     END;
  1140.  
  1141. {--------------------------------------------------------------------------------------------------}
  1142. {$S DlgRes}
  1143.  
  1144. PROCEDURE TRadio.DoChoice(origView: TView;
  1145.                           itsChoice: INTEGER);
  1146.  
  1147.     BEGIN
  1148.     IF (itsChoice = mRadioHit) & NOT isOn THEN
  1149.         Toggle(kRedraw);
  1150.     INHERITED DoChoice(origView, itsChoice);
  1151.     END;
  1152.  
  1153. {--------------------------------------------------------------------------------------------------}
  1154. {$S DlgRes}
  1155.  
  1156. FUNCTION TRadio.isOn: BOOLEAN;
  1157.  
  1158.     BEGIN
  1159.     isOn := GetLongVal <> 0;
  1160.     END;
  1161.  
  1162. {--------------------------------------------------------------------------------------------------}
  1163. {$S DlgRes}
  1164.  
  1165. PROCEDURE TRadio.SetState(state, redraw: BOOLEAN);
  1166.  
  1167.     BEGIN
  1168.     SetLongVal(ORD(state), redraw);
  1169.     END;
  1170.  
  1171. {--------------------------------------------------------------------------------------------------}
  1172. {$S DlgRes}
  1173.  
  1174. PROCEDURE TRadio.Toggle(redraw: BOOLEAN);
  1175.  
  1176.     BEGIN
  1177.     SetLongVal(ORD(NOT isOn), redraw);
  1178.     END;
  1179.  
  1180. {--------------------------------------------------------------------------------------------------}
  1181. {$S DlgRes}
  1182.  
  1183. PROCEDURE TRadio.ToggleIf(matchState, redraw: BOOLEAN);
  1184.  
  1185.     BEGIN
  1186.     IF isOn = matchState THEN
  1187.         SetLongVal(ORD(NOT isOn), redraw);
  1188.     END;
  1189.  
  1190. {--------------------------------------------------------------------------------------------------}
  1191. {$S DlgFields}
  1192.  
  1193. PROCEDURE TRadio.Fields(PROCEDURE DoToField(fieldName: Str255;
  1194.                                             fieldAddr: Ptr;
  1195.                                             fieldType: INTEGER)); OVERRIDE;
  1196.  
  1197.     BEGIN
  1198.     DoToField('TRadio', NIL, bClass);
  1199.  
  1200.     INHERITED Fields(DoToField);
  1201.     END;
  1202.  
  1203. {--------------------------------------------------------------------------------------------------}
  1204. {$S DlgOpen}
  1205.  
  1206. PROCEDURE TCluster.ICluster(itsSuperView: TView;
  1207.                             itsLocation, itsSize: VPoint;
  1208.                             itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1209.                             itsRsrcID, itsIndex: INTEGER);
  1210.  
  1211.     VAR
  1212.         aString:            Str255;
  1213.         fi:                 FailInfo;
  1214.  
  1215.     PROCEDURE HandleFailure(error: OSErr;
  1216.                             message: LONGINT);
  1217.  
  1218.         BEGIN
  1219.         Free;
  1220.         END;
  1221.  
  1222.     BEGIN
  1223.     fDataHandle := NIL;
  1224.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1225.     fRsrcID := itsRsrcID;
  1226.     fIndex := itsIndex;
  1227.     IF fRsrcID <> kNoResource THEN
  1228.         BEGIN
  1229.         CatchFailures(fi, HandleFailure);
  1230.         GetIndString(aString, fRsrcID, fIndex);
  1231.         FailResError;
  1232.         Success(fi);
  1233.         SetLabel(aString, kDontRedraw);
  1234.         END;
  1235.     ViewEnable(False, kDontRedraw);                     { Default is not to enable hit testing }
  1236.     fDefChoice := mClusterHit;
  1237.     END;
  1238.  
  1239. {--------------------------------------------------------------------------------------------------}
  1240. {$S DlgOpen}
  1241.  
  1242. PROCEDURE TCluster.IRes(itsDocument: TDocument;
  1243.                         itsSuperView: TView;
  1244.                         VAR itsParams: Ptr); OVERRIDE;
  1245.  
  1246.     BEGIN
  1247.     fDataHandle := NIL;
  1248.     INHERITED IRes(NIL, itsSuperView, itsParams);
  1249.     fDefChoice := mClusterHit;
  1250.  
  1251.     WITH ClusterTemplatePtr(itsParams)^ DO
  1252.         SetLabel(itsLabel, kDontRedraw);
  1253.  
  1254.     OffsetPtrWStr(itsParams, SIZEOF(ClusterTemplate));
  1255.     END;
  1256.  
  1257. {--------------------------------------------------------------------------------------------------}
  1258. {$S MAWriteRes}
  1259.  
  1260. PROCEDURE TCluster.WRes(theResource: ViewRsrcHndl;
  1261.                         VAR itsParams: Ptr); OVERRIDE;
  1262.  
  1263.     VAR
  1264.         theLabel:            Str255;
  1265.         clPtr:                ClusterTemplatePtr;
  1266.  
  1267.     BEGIN
  1268.     INHERITED WRes(theResource, itsParams);
  1269.  
  1270.     GetLabel(theLabel);
  1271.  
  1272.     clPtr := ClusterTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(ClusterTemplate),
  1273.                                               Length(theLabel)));
  1274.  
  1275.     { clPtr^.itsLabel := theLabel; }
  1276.     CopyStr255(theLabel, PRStr(clPtr^.itsLabel));
  1277.     END;
  1278.  
  1279. {--------------------------------------------------------------------------------------------------}
  1280. {$S MAWriteRes}
  1281.  
  1282. PROCEDURE TCluster.WriteRes(theResource: ViewRsrcHndl;
  1283.                             VAR itsParams: Ptr); OVERRIDE;
  1284.  
  1285.     BEGIN
  1286.     gWResSignature := 'clus'; gWResType := 'TCluster';
  1287.     WRes(theResource, itsParams);
  1288.     END;
  1289.  
  1290. {--------------------------------------------------------------------------------------------------}
  1291. {$S DlgClose}
  1292.  
  1293. PROCEDURE TCluster.Free; OVERRIDE;
  1294.  
  1295.     BEGIN
  1296.     ReleaseLabel;
  1297.     INHERITED Free;
  1298.     END;
  1299.  
  1300. {--------------------------------------------------------------------------------------------------}
  1301. {$S DlgRes}
  1302.  
  1303. PROCEDURE TCluster.DoChoice(origView: TView;
  1304.                             itsChoice: INTEGER); OVERRIDE;
  1305.  
  1306.     PROCEDURE ResetRadios(aView: TView);
  1307.  
  1308.         BEGIN
  1309.         IF Member(aView, TRadio) &                        { If the subview is a TRadio, and… }
  1310.            (aView <> origView) THEN                     { …it's not the calling radio… }
  1311.             TRadio(aView).SetState(False, kRedraw);     { …set it off and redraw it }
  1312.         END;
  1313.  
  1314.     BEGIN
  1315.     IF (itsChoice = mRadioHit) &                        { If we got this far, a radio's changed
  1316.                                                          state }
  1317.        (origView.fSuperView = SELF) THEN                { Only worry about it if it's our subview! }
  1318.         EachSubView(ResetRadios);                        { Reset everybody except the calling radio }
  1319.     INHERITED DoChoice(origView, itsChoice);
  1320.     END;
  1321.  
  1322. {--------------------------------------------------------------------------------------------------}
  1323. {$S DlgRes}
  1324.  
  1325. PROCEDURE TCluster.Draw(area: Rect); OVERRIDE;
  1326.  
  1327.     VAR
  1328.         fontHt:             INTEGER;
  1329.         labelWd:            INTEGER;
  1330.         oldTop:             INTEGER;
  1331.         fInfo:                FontInfo;
  1332.         theFrame:            Rect;
  1333.         theText:            Str255;
  1334.         aDialogView:        TDialogView;
  1335.         aTextStyle:         TextStyle;
  1336.  
  1337.     BEGIN
  1338.     IF qDebug THEN
  1339.         AssumeFocused;
  1340.  
  1341.     IF fDataHandle <> NIL THEN
  1342.         BEGIN
  1343.         {$Push} {$H-}
  1344.         WITH fPenSize DO
  1345.             PenSize(h, v);
  1346.         {$Pop}
  1347.         GetFontInfo(fInfo);                             { Determine label's height }
  1348.         WITH fInfo DO
  1349.             fontHt := ascent + descent + leading;
  1350.         ControlArea(theFrame);                            { Get the control's extent }
  1351.         oldTop := theFrame.top;
  1352.         {$Push} {$H-}
  1353.         WITH fPenSize DO
  1354.             InsetRect(theFrame, h + 1, v + 1);             { Inset the frame a little }
  1355.         {$Pop}
  1356.         theFrame.top := oldTop + BSR(fontHt, 1);        { Bump top so it cuts label in half }
  1357.  
  1358.         FrameRect(theFrame);                            { Draw the frame }
  1359.  
  1360.         CopyStr255(fDataHandle^^, @theText);
  1361.         aDialogView := TDialogView(GetDialogView);
  1362.         IF aDialogView <> NIL THEN
  1363.             aDialogView.ReplaceText(theText);
  1364.  
  1365.         { !!! Really need a method to draw the title }
  1366.         labelWd := StringWidth(theText) + 8;
  1367.         SetRect(theFrame, 16, 0, labelWd + 16, fontHt);
  1368.         MATextBox(Ptr(ORD4(@theText) + 1), Length(theText), theFrame, teJustCenter, kNoAutoWrap, NIL,
  1369.                 kEraseFirst, kNoSpaceForCaret);
  1370.         END;
  1371.     INHERITED Draw(area);                                { Let parents have a chance to draw too }
  1372.     END;
  1373.  
  1374. {--------------------------------------------------------------------------------------------------}
  1375. {$S DlgNonRes}
  1376.  
  1377. PROCEDURE TCluster.GetLabel(VAR theLabel: Str255);
  1378.  
  1379.     BEGIN
  1380.     IF fDataHandle <> NIL THEN
  1381.         theLabel := fDataHandle^^
  1382.     ELSE
  1383.         theLabel := '';
  1384.     END;
  1385.  
  1386. {--------------------------------------------------------------------------------------------------}
  1387. {$S DlgNonRes}
  1388.  
  1389. PROCEDURE TCluster.ReleaseLabel;
  1390.  
  1391.     BEGIN
  1392.     Handle(fDataHandle) := DisposeIfHandle(fDataHandle);
  1393.  
  1394.     fRsrcID := kNoResource;
  1395.     END;
  1396.  
  1397. {--------------------------------------------------------------------------------------------------}
  1398. {$S DlgRes}
  1399.  
  1400. FUNCTION TCluster.ReportCurrent: IDType;
  1401.  
  1402.     VAR
  1403.         rView:                TView;
  1404.  
  1405.     FUNCTION FindRadio(aView: TView): BOOLEAN;
  1406.  
  1407.         BEGIN
  1408.         FindRadio := Member(aView, TRadio) & TRadio(aView).isOn;
  1409.         END;
  1410.  
  1411.     BEGIN
  1412.     rView := FirstSubViewThat(FindRadio);
  1413.     IF rView <> NIL THEN
  1414.         ReportCurrent := rView.fIdentifier
  1415.     ELSE
  1416.         ReportCurrent := kNoIdentifier;
  1417.     END;
  1418.  
  1419. {--------------------------------------------------------------------------------------------------}
  1420. {$S DlgNonRes}
  1421.  
  1422. PROCEDURE TCluster.SetLabel(theLabel: Str255;
  1423.                             redraw: BOOLEAN);
  1424.  
  1425.     BEGIN
  1426.     ReleaseLabel;
  1427.     IF theLabel <> '' THEN
  1428.         BEGIN
  1429.         fDataHandle := NewString(theLabel);
  1430.         IF MemError <> noErr THEN
  1431.             fDataHandle := NIL;
  1432.         END;
  1433.     IF redraw THEN
  1434.         ForceRedraw;
  1435.     END;
  1436.  
  1437. {--------------------------------------------------------------------------------------------------}
  1438. {$S DlgFields}
  1439.  
  1440. PROCEDURE TCluster.Fields(PROCEDURE DoToField(fieldName: Str255;
  1441.                                               fieldAddr: Ptr;
  1442.                                               fieldType: INTEGER)); OVERRIDE;
  1443.  
  1444.     VAR
  1445.         aString:            Str255;
  1446.  
  1447.     BEGIN
  1448.     DoToField('TCluster', NIL, bClass);
  1449.     DoToField('fRsrcID', @fRsrcID, bInteger);
  1450.     DoToField('fIndex', @fIndex, bInteger);
  1451.     DoToField('fDataHandle', @fDataHandle, bHandle);
  1452.     IF fDataHandle <> NIL THEN
  1453.         BEGIN
  1454.         aString := fDataHandle^^;
  1455.         DoToField('fDataHandle^^', @aString, bString);
  1456.         END;
  1457.  
  1458.     INHERITED Fields(DoToField);
  1459.     END;
  1460.  
  1461. {--------------------------------------------------------------------------------------------------}
  1462. {$S DlgOpen}
  1463.  
  1464. PROCEDURE TIcon.IIcon(itsSuperView: TView;
  1465.                       itsLocation, itsSize: VPoint;
  1466.                       itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1467.                       itsRsrcID: INTEGER;
  1468.                       preferColor: BOOLEAN);
  1469.  
  1470.     VAR
  1471.         fi:                 FailInfo;
  1472.  
  1473.     PROCEDURE HandleFailure(error: OSErr;
  1474.                             message: LONGINT);
  1475.  
  1476.         BEGIN
  1477.         Free;
  1478.         END;
  1479.  
  1480.     BEGIN
  1481.     fDataHandle := NIL;
  1482.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1483.     fPreferColor := preferColor;
  1484.     fRsrcID := itsRsrcID;
  1485.     IF fRsrcID <> kNoResource THEN
  1486.         BEGIN
  1487.         CatchFailures(fi, HandleFailure);
  1488.         IF fPreferColor THEN
  1489.             IF qNeedsColorQD | gConfiguration.hasColorQD THEN
  1490.                 fDataHandle := Handle(GetCIcon(fRsrcID));
  1491.         IF fDataHandle = NIL THEN
  1492.             BEGIN
  1493.             fDataHandle := GetIcon(fRsrcID);
  1494.             IF fDataHandle <> NIL THEN
  1495.                 fPreferColor := NOT kPreferColor;        { Either can't or won't }
  1496.             END;
  1497.         FailResError;
  1498.         Success(fi);
  1499.         END;
  1500.     ViewEnable(False, kDontRedraw);                     { Default is to not enable hit testing }
  1501.     fDefChoice := mIconHit;
  1502.     END;
  1503.  
  1504. {--------------------------------------------------------------------------------------------------}
  1505. {$S DlgOpen}
  1506.  
  1507. PROCEDURE TIcon.IRes(itsDocument: TDocument;
  1508.                      itsSuperView: TView;
  1509.                      VAR itsParams: Ptr); OVERRIDE;
  1510.  
  1511.     VAR
  1512.         fi:                 FailInfo;
  1513.  
  1514.     PROCEDURE HandleFailure(error: OSErr;
  1515.                             message: LONGINT);
  1516.  
  1517.         BEGIN
  1518.         Free;
  1519.         END;
  1520.  
  1521.     BEGIN
  1522.     fDataHandle := NIL;
  1523.     INHERITED IRes(NIL, itsSuperView, itsParams);
  1524.  
  1525.     WITH IconTemplatePtr(itsParams)^ DO
  1526.         BEGIN
  1527.         fPreferColor := preferColor;
  1528.         fRsrcID := rsrcID;
  1529.         END;
  1530.     IF fRsrcID <> kNoResource THEN
  1531.         BEGIN
  1532.         CatchFailures(fi, HandleFailure);
  1533.         IF fPreferColor THEN
  1534.             IF qNeedsColorQD | gConfiguration.hasColorQD THEN
  1535.                 fDataHandle := Handle(GetCIcon(fRsrcID));
  1536.         IF fDataHandle = NIL THEN
  1537.             BEGIN
  1538.             fDataHandle := GetIcon(fRsrcID);
  1539.             IF fDataHandle <> NIL THEN
  1540.                 fPreferColor := NOT kPreferColor;        { Either can't or won't }
  1541.             END;
  1542.         { Don't die because resource not found - just return NIL handle }
  1543.         FailResError;
  1544.         Success(fi);
  1545.         END;
  1546.     fDefChoice := mIconHit;
  1547.  
  1548.     OffsetPtr(itsParams, SIZEOF(IconTemplate));
  1549.     END;
  1550.  
  1551. {--------------------------------------------------------------------------------------------------}
  1552. {$S MAWriteRes}
  1553.  
  1554. PROCEDURE TIcon.WRes(theResource: ViewRsrcHndl;
  1555.                      VAR itsParams: Ptr); OVERRIDE;
  1556.  
  1557.     VAR
  1558.         icPtr:                IconTemplatePtr;
  1559.  
  1560.     BEGIN
  1561.     INHERITED WRes(theResource, itsParams);
  1562.  
  1563.     icPtr := IconTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(IconTemplate)));
  1564.  
  1565.     WITH icPtr^ DO
  1566.         BEGIN
  1567.         preferColor := fPreferColor;
  1568.         {$IFC qDebug}
  1569.         IF fRsrcID = kNoResource THEN
  1570.             WRITELN('Tried to write TIcon with no resource ID.');
  1571.         {$ENDC}
  1572.         rsrcID := fRsrcID;
  1573.         END;
  1574.     END;
  1575.  
  1576. {--------------------------------------------------------------------------------------------------}
  1577. {$S MAWriteRes}
  1578.  
  1579. PROCEDURE TIcon.WriteRes(theResource: ViewRsrcHndl;
  1580.                          VAR itsParams: Ptr); OVERRIDE;
  1581.  
  1582.     BEGIN
  1583.     gWResSignature := 'icon'; gWResType := 'TIcon';
  1584.     WRes(theResource, itsParams);
  1585.     END;
  1586.  
  1587. {--------------------------------------------------------------------------------------------------}
  1588. {$S DlgClose}
  1589.  
  1590. PROCEDURE TIcon.Free; OVERRIDE;
  1591.  
  1592.     BEGIN
  1593.     ReleaseIcon;
  1594.  
  1595.     INHERITED Free;
  1596.     END;
  1597.  
  1598. {--------------------------------------------------------------------------------------------------}
  1599. {$S DlgRes}
  1600.  
  1601. PROCEDURE TIcon.Draw(area: Rect); OVERRIDE;
  1602.  
  1603.     VAR
  1604.         oldState: SignedByte;
  1605.         theRect: Rect;
  1606.         aPixMap: PixMap;
  1607.         aBitMapPtr: BitMapPtr;
  1608.         srcRect: Rect;
  1609.  
  1610.     BEGIN
  1611.     IF fDataHandle <> NIL THEN
  1612.         BEGIN
  1613.         IF fRsrcID <> kNoResource THEN
  1614.             LoadResource(fDataHandle);
  1615.         IF fDataHandle^ <> NIL THEN            { If there's room for the icon… }
  1616.             BEGIN
  1617.             PenNormal;                        { NECESSARY? }
  1618.             ControlArea(theRect);
  1619.             oldState := GetHandleBits(fDataHandle);
  1620.             HNoPurge(fDataHandle);
  1621.             HLock(fDataHandle);
  1622.  
  1623.             IF fPreferColor THEN
  1624.                 BEGIN
  1625.  
  1626.                 { We can't use PlotCIcon here because it can't be written to a picture }
  1627.                 { and when WriteToDeskScrap is called, the icon is plotted on the }
  1628.                 { desktop rather than in the picture.  So instead, pick apart the color }
  1629.                 { icon handle and use copybits, ignoring the mask. }
  1630.  
  1631.                 aPixMap := CIconHandle(fDataHandle)^^.iconPMap;
  1632.                 HLock(CIconHandle(fDataHandle)^^.iconData);
  1633.                 aPixMap.baseAddr := CIconHandle(fDataHandle)^^.iconData^;
  1634.                 srcRect := aPixMap.bounds;
  1635.                 aBitMapPtr := @aPixMap;
  1636.                 CopyBits(aBitMapPtr^, thePort^.portBits, srcRect, theRect, srcCopy, NIL);
  1637.                 HUnLock(CIconHandle(fDataHandle)^^.iconData);
  1638.                 END
  1639.             ELSE
  1640.                 PlotIcon(theRect, fDataHandle);
  1641.  
  1642.             SetHandleBits(fDataHandle, oldState);
  1643.             END;
  1644.         END;
  1645.  
  1646.     INHERITED Draw(area);
  1647.     END;
  1648.  
  1649. {--------------------------------------------------------------------------------------------------}
  1650. {$S DlgNonRes}
  1651.  
  1652. PROCEDURE TIcon.ReleaseIcon;
  1653.  
  1654.     BEGIN
  1655.     fRsrcID := kNoResource;
  1656.     IF fDataHandle <> NIL THEN
  1657.         BEGIN
  1658.         IF fPreferColor THEN
  1659.             DisposCIcon(CIconHandle(fDataHandle))
  1660.         ELSE
  1661.             HPurge(fDataHandle);
  1662.         fDataHandle := NIL;
  1663.         END;
  1664.     END;
  1665.  
  1666. {--------------------------------------------------------------------------------------------------}
  1667. {$S DlgNonRes}
  1668.  
  1669. PROCEDURE TIcon.SetIcon(theIcon: Handle;
  1670.                         redraw: BOOLEAN);
  1671.  
  1672.     BEGIN
  1673.     ReleaseIcon;
  1674.     fDataHandle := theIcon;
  1675.     IF redraw THEN
  1676.         ForceRedraw;
  1677.     END;
  1678.  
  1679. {--------------------------------------------------------------------------------------------------}
  1680. {$S DlgFields}
  1681.  
  1682. PROCEDURE TIcon.Fields(PROCEDURE DoToField(fieldName: Str255;
  1683.                                            fieldAddr: Ptr;
  1684.                                            fieldType: INTEGER)); OVERRIDE;
  1685.  
  1686.     BEGIN
  1687.     DoToField('TIcon', NIL, bClass);
  1688.     DoToField('fPreferColor', @fPreferColor, bBoolean);
  1689.     DoToField('fRsrcID', @fRsrcID, bInteger);
  1690.     DoToField('fDataHandle', @fDataHandle, bHandle);
  1691.  
  1692.     INHERITED Fields(DoToField);
  1693.     END;
  1694.  
  1695. {--------------------------------------------------------------------------------------------------}
  1696. {$S DlgOpen}
  1697.  
  1698. PROCEDURE TPattern.IPattern(itsSuperView: TView;
  1699.                             itsLocation, itsSize: VPoint;
  1700.                             itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1701.                             itsRsrcID: INTEGER;
  1702.                             preferColor: BOOLEAN);
  1703.  
  1704.     VAR
  1705.         fi:                 FailInfo;
  1706.  
  1707.     PROCEDURE HandleFailure(error: OSErr;
  1708.                             message: LONGINT);
  1709.  
  1710.         BEGIN
  1711.         Free;
  1712.         END;
  1713.  
  1714.     BEGIN
  1715.     fDataHandle := NIL;
  1716.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1717.     fPreferColor := preferColor;
  1718.     fRsrcID := itsRsrcID;
  1719.     IF fRsrcID <> kNoResource THEN
  1720.         BEGIN
  1721.         CatchFailures(fi, HandleFailure);
  1722.         IF fPreferColor THEN
  1723.             IF qNeedsColorQD | gConfiguration.hasColorQD THEN
  1724.                 fDataHandle := Handle(GetPixPat(fRsrcID));
  1725.         IF fDataHandle = NIL THEN
  1726.             BEGIN
  1727.             fDataHandle := Handle(GetPattern(fRsrcID));
  1728.             IF fDataHandle <> NIL THEN
  1729.                 fPreferColor := NOT kPreferColor;        { Either can't or won't }
  1730.             END;
  1731.         FailResError;
  1732.         Success(fi);
  1733.         END;
  1734.     ViewEnable(False, kDontRedraw);                     { Default is to not enable hit testing }
  1735.     fDefChoice := mPatternHit;
  1736.     END;
  1737.  
  1738. {--------------------------------------------------------------------------------------------------}
  1739. {$S DlgOpen}
  1740.  
  1741. PROCEDURE TPattern.IRes(itsDocument: TDocument;
  1742.                         itsSuperView: TView;
  1743.                         VAR itsParams: Ptr); OVERRIDE;
  1744.  
  1745.     VAR
  1746.         fi:                 FailInfo;
  1747.  
  1748.     PROCEDURE HandleFailure(error: OSErr;
  1749.                             message: LONGINT);
  1750.  
  1751.         BEGIN
  1752.         Free;
  1753.         END;
  1754.  
  1755.     BEGIN
  1756.     fDataHandle := NIL;
  1757.     INHERITED IRes(NIL, itsSuperView, itsParams);
  1758.  
  1759.     WITH PatternTemplatePtr(itsParams)^ DO
  1760.         BEGIN
  1761.         fPreferColor := preferColor;
  1762.         fRsrcID := rsrcID;
  1763.         END;
  1764.     IF fRsrcID <> kNoResource THEN
  1765.         BEGIN
  1766.         CatchFailures(fi, HandleFailure);
  1767.         IF fPreferColor THEN
  1768.             IF qNeedsColorQD | gConfiguration.hasColorQD THEN
  1769.                 fDataHandle := Handle(GetPixPat(fRsrcID));
  1770.         IF fDataHandle = NIL THEN
  1771.             BEGIN
  1772.             fDataHandle := Handle(GetPattern(fRsrcID));
  1773.             IF fDataHandle <> NIL THEN
  1774.                 fPreferColor := NOT kPreferColor;        { Either can't or won't }
  1775.             END;
  1776.         FailResError;
  1777.         Success(fi);
  1778.         END;
  1779.     fDefChoice := mPatternHit;
  1780.  
  1781.     OffsetPtr(itsParams, SIZEOF(PatternTemplate));
  1782.     END;
  1783.  
  1784. {--------------------------------------------------------------------------------------------------}
  1785. {$S MAWriteRes}
  1786.  
  1787. PROCEDURE TPattern.WRes(theResource: ViewRsrcHndl;
  1788.                         VAR itsParams: Ptr); OVERRIDE;
  1789.  
  1790.     VAR
  1791.         ptPtr:                PatternTemplatePtr;
  1792.  
  1793.     BEGIN
  1794.     INHERITED WRes(theResource, itsParams);
  1795.  
  1796.     ptPtr := PatternTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(PatternTemplate)));
  1797.  
  1798.     WITH ptPtr^ DO
  1799.         BEGIN
  1800.         preferColor := fPreferColor;
  1801.         {$IFC qDebug}
  1802.         IF fRsrcID = kNoResource THEN
  1803.             WRITELN('Tried to write TPattern with no resource ID.');
  1804.         {$ENDC}
  1805.         rsrcID := fRsrcID;
  1806.         END;
  1807.     END;
  1808.  
  1809. {--------------------------------------------------------------------------------------------------}
  1810. {$S MAWriteRes}
  1811.  
  1812. PROCEDURE TPattern.WriteRes(theResource: ViewRsrcHndl;
  1813.                             VAR itsParams: Ptr); OVERRIDE;
  1814.  
  1815.     BEGIN
  1816.     gWResSignature := 'patn'; gWResType := 'TPattern';
  1817.     WRes(theResource, itsParams);
  1818.     END;
  1819.  
  1820. {--------------------------------------------------------------------------------------------------}
  1821. {$S DlgClose}
  1822.  
  1823. PROCEDURE TPattern.Free; OVERRIDE;
  1824.  
  1825.     BEGIN
  1826.     ReleasePattern;
  1827.  
  1828.     INHERITED Free;
  1829.     END;
  1830.  
  1831. {--------------------------------------------------------------------------------------------------}
  1832. {$S DlgRes}
  1833.  
  1834. PROCEDURE TPattern.Draw(area: Rect); OVERRIDE;
  1835.  
  1836.     VAR
  1837.         wasLocked:            BOOLEAN;
  1838.         theRect:            Rect;
  1839.  
  1840.     BEGIN
  1841.     IF fDataHandle <> NIL THEN
  1842.         BEGIN
  1843.         IF (fRsrcID <> kNoResource) & NOT fPreferColor THEN { Pixpat handles <> resource handles }
  1844.             LoadResource(fDataHandle);
  1845.         IF fDataHandle^ <> NIL THEN                     { If there's room for the pattern… }
  1846.             BEGIN
  1847.             PenNormal;                                    { NECESSARY? }
  1848.             ControlArea(theRect);
  1849.             wasLocked := IsHandleLocked(fDataHandle);    { Remember current lock state }
  1850.             IF NOT wasLocked THEN
  1851.                 HLock(fDataHandle);                     { Because FillRect may move memory }
  1852.             IF fPreferColor THEN
  1853.                 FillCRect(theRect, PixPatHandle(fDataHandle))
  1854.             ELSE
  1855.                 FillRect(theRect, PatHandle(fDataHandle)^^);
  1856.             IF NOT wasLocked THEN
  1857.                 HUnLock(fDataHandle);                    { restore handle's unlocked state }
  1858.             END
  1859.         END;
  1860.  
  1861.     INHERITED Draw(area);
  1862.     END;
  1863.  
  1864. {--------------------------------------------------------------------------------------------------}
  1865. {$S DlgNonRes}
  1866.  
  1867. PROCEDURE TPattern.ReleasePattern;
  1868.  
  1869.     BEGIN
  1870.     fRsrcID := kNoResource;
  1871.     IF fDataHandle <> NIL THEN
  1872.         BEGIN
  1873.         IF fPreferColor THEN
  1874.             DisposPixPat(PixPatHandle(fDataHandle))
  1875.         ELSE
  1876.             HPurge(fDataHandle);
  1877.         fDataHandle := NIL;
  1878.         END;
  1879.     END;
  1880.  
  1881. {--------------------------------------------------------------------------------------------------}
  1882. {$S DlgNonRes}
  1883.  
  1884. PROCEDURE TPattern.SetPattern(thePattern: Handle;
  1885.                               redraw: BOOLEAN);
  1886.  
  1887.     BEGIN
  1888.     ReleasePattern;
  1889.     fDataHandle := thePattern;
  1890.     IF redraw THEN
  1891.         ForceRedraw;
  1892.     END;
  1893.  
  1894. {--------------------------------------------------------------------------------------------------}
  1895. {$S DlgFields}
  1896.  
  1897. PROCEDURE TPattern.Fields(PROCEDURE DoToField(fieldName: Str255;
  1898.                                               fieldAddr: Ptr;
  1899.                                               fieldType: INTEGER)); OVERRIDE;
  1900.  
  1901.     BEGIN
  1902.     DoToField('TPattern', NIL, bClass);
  1903.     DoToField('fPreferColor', @fPreferColor, bBoolean);
  1904.     DoToField('fRsrcID', @fRsrcID, bInteger);
  1905.     DoToField('fDataHandle', @fDataHandle, bHandle);
  1906.  
  1907.     INHERITED Fields(DoToField);
  1908.     END;
  1909.  
  1910. {--------------------------------------------------------------------------------------------------}
  1911. {$S DlgOpen}
  1912.  
  1913. PROCEDURE TPicture.IPicture(itsSuperView: TView;
  1914.                             itsLocation, itsSize: VPoint;
  1915.                             itsHSizeDet, itsVSizeDet: SizeDeterminer;
  1916.                             itsRsrcID: INTEGER);
  1917.  
  1918.     VAR
  1919.         fi:                 FailInfo;
  1920.  
  1921.     PROCEDURE HandleFailure(error: OSErr;
  1922.                             message: LONGINT);
  1923.  
  1924.         BEGIN
  1925.         Free;
  1926.         END;
  1927.  
  1928.     BEGIN
  1929.     fDataHandle := NIL;
  1930.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  1931.     fRsrcID := itsRsrcID;
  1932.     IF fRsrcID <> kNoResource THEN
  1933.         BEGIN
  1934.         CatchFailures(fi, HandleFailure);
  1935.         fDataHandle := GetPicture(fRsrcID);
  1936.         FailResError;
  1937.         Success(fi);
  1938.         END;
  1939.     ViewEnable(False, kDontRedraw);                     { Default is to not enable hit testing }
  1940.     fDefChoice := mPictureHit;
  1941.     END;
  1942.  
  1943. {--------------------------------------------------------------------------------------------------}
  1944. {$S DlgOpen}
  1945.  
  1946. PROCEDURE TPicture.IRes(itsDocument: TDocument;
  1947.                         itsSuperView: TView;
  1948.                         VAR itsParams: Ptr); OVERRIDE;
  1949.  
  1950.     VAR
  1951.         fi:                 FailInfo;
  1952.  
  1953.     PROCEDURE HandleFailure(error: OSErr;
  1954.                             message: LONGINT);
  1955.  
  1956.         BEGIN
  1957.         Free;
  1958.         END;
  1959.  
  1960.     BEGIN
  1961.     fDataHandle := NIL;
  1962.     INHERITED IRes(NIL, itsSuperView, itsParams);
  1963.  
  1964.     fRsrcID := PictureTemplatePtr(itsParams)^.rsrcID;
  1965.     IF fRsrcID <> kNoResource THEN
  1966.         BEGIN
  1967.         CatchFailures(fi, HandleFailure);
  1968.         fDataHandle := GetPicture(fRsrcID);
  1969.         FailResError;
  1970.         Success(fi);
  1971.         END;
  1972.     fDefChoice := mPictureHit;
  1973.  
  1974.     OffsetPtr(itsParams, SIZEOF(PictureTemplate));
  1975.     END;
  1976.  
  1977. {--------------------------------------------------------------------------------------------------}
  1978. {$S MAWriteRes}
  1979.  
  1980. PROCEDURE TPicture.WRes(theResource: ViewRsrcHndl;
  1981.                         VAR itsParams: Ptr); OVERRIDE;
  1982.  
  1983.     VAR
  1984.         pcPtr:                PictureTemplatePtr;
  1985.  
  1986.     BEGIN
  1987.     INHERITED WRes(theResource, itsParams);
  1988.  
  1989.     pcPtr := PictureTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(PictureTemplate)));
  1990.  
  1991.     {$IFC qDebug}
  1992.     IF fRsrcID = kNoResource THEN
  1993.         WRITELN('Tried to write TPicture with no resource ID.');
  1994.     {$ENDC}
  1995.     pcPtr^.rsrcID := fRsrcID;
  1996.     END;
  1997.  
  1998. {--------------------------------------------------------------------------------------------------}
  1999. {$S MAWriteRes}
  2000.  
  2001. PROCEDURE TPicture.WriteRes(theResource: ViewRsrcHndl;
  2002.                             VAR itsParams: Ptr); OVERRIDE;
  2003.  
  2004.     BEGIN
  2005.     gWResSignature := 'pict'; gWResType := 'TPicture';
  2006.     WRes(theResource, itsParams);
  2007.     END;
  2008.  
  2009. {--------------------------------------------------------------------------------------------------}
  2010. {$S DlgClose}
  2011.  
  2012. PROCEDURE TPicture.Free; OVERRIDE;
  2013.  
  2014.     BEGIN
  2015.     ReleasePicture;
  2016.  
  2017.     INHERITED Free;
  2018.     END;
  2019.  
  2020. {--------------------------------------------------------------------------------------------------}
  2021. {$S DlgRes}
  2022.  
  2023. PROCEDURE TPicture.Draw(area: Rect); OVERRIDE;
  2024.  
  2025.     VAR
  2026.         oldState:            SignedByte;
  2027.         theRect:            Rect;
  2028.  
  2029.     BEGIN
  2030.     IF fDataHandle <> NIL THEN
  2031.         BEGIN
  2032.         IF fRsrcID <> kNoResource THEN
  2033.             LoadResource(Handle(fDataHandle));
  2034.         IF fDataHandle^ <> NIL THEN                     { If there's room for the picture… }
  2035.             BEGIN
  2036.             ControlArea(theRect);
  2037.             oldState := GetHandleBits(Handle(fDataHandle));
  2038.             HNoPurge(Handle(fDataHandle));
  2039.             PenNormal;                                    { ??? NECESSARY ??? }
  2040.             DrawPicture(fDataHandle, theRect);
  2041.             SetHandleBits(Handle(fDataHandle), oldState);
  2042.             END;
  2043.         END;
  2044.     INHERITED Draw(area);
  2045.     END;
  2046.  
  2047. {--------------------------------------------------------------------------------------------------}
  2048. {$S DlgNonRes}
  2049.  
  2050. PROCEDURE TPicture.ReleasePicture;
  2051.  
  2052.     BEGIN
  2053.     fRsrcID := kNoResource;
  2054.     IF fDataHandle <> NIL THEN
  2055.         BEGIN
  2056.         HPurge(Handle(fDataHandle));
  2057.         fDataHandle := NIL;
  2058.         END;
  2059.     END;
  2060.  
  2061. {--------------------------------------------------------------------------------------------------}
  2062. {$S DlgNonRes}
  2063.  
  2064. PROCEDURE TPicture.SetPicture(thePicture: PicHandle;
  2065.                               redraw: BOOLEAN);
  2066.  
  2067.     BEGIN
  2068.     ReleasePicture;
  2069.     fDataHandle := thePicture;
  2070.     IF redraw THEN
  2071.         ForceRedraw;
  2072.     END;
  2073.  
  2074. {--------------------------------------------------------------------------------------------------}
  2075. {$S DlgFields}
  2076.  
  2077. PROCEDURE TPicture.Fields(PROCEDURE DoToField(fieldName: Str255;
  2078.                                               fieldAddr: Ptr;
  2079.                                               fieldType: INTEGER)); OVERRIDE;
  2080.  
  2081.     BEGIN
  2082.     DoToField('TPicture', NIL, bClass);
  2083.     DoToField('fRsrcID', @fRsrcID, bInteger);
  2084.     DoToField('fDataHandle', @fDataHandle, bHandle);
  2085.  
  2086.     INHERITED Fields(DoToField);
  2087.     END;
  2088.  
  2089. {--------------------------------------------------------------------------------------------------}
  2090. {$S DlgOpen}
  2091.  
  2092. PROCEDURE TPopup.IPopup(itsSuperView: TView;
  2093.                         itsLocation, itsSize: VPoint;
  2094.                         itsHSizeDet, itsVSizeDet: SizeDeterminer;
  2095.                         itsRsrcID, itsCurrentItem, itsItemOffset: INTEGER);
  2096.  
  2097.     VAR
  2098.         fi:                 FailInfo;
  2099.         aMenu:                MenuHandle;
  2100.  
  2101.     PROCEDURE HandleFailure(error: OSErr;
  2102.                             message: LONGINT);
  2103.  
  2104.         BEGIN
  2105.         Free;
  2106.         END;
  2107.  
  2108.     BEGIN
  2109.     fMenuHandle := NIL;
  2110.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2111.  
  2112.     IF qNeedsHierarchicalMenus | gConfiguration.hasHierarchicalMenus THEN
  2113.         BEGIN
  2114.         fCurrentItem := Max(1, itsCurrentItem);
  2115.         fItemOffset := itsItemOffset;
  2116.         IF itsRsrcID <> kNoResource THEN
  2117.             BEGIN
  2118.             CatchFailures(fi, HandleFailure);
  2119.             aMenu := GetMenu(itsRsrcID);
  2120.             { Don't die because resource not found - just return NIL handle }
  2121.             FailResError;
  2122.             HNoPurge(Handle(aMenu));
  2123.             SetPopup(aMenu, itsRsrcID, itsCurrentItem, False);
  2124.             Success(fi);
  2125.             END
  2126.         ELSE
  2127.             BEGIN
  2128.             fRsrcID := kNoResource;
  2129.             fMenuID := kNoResource;
  2130.             END;
  2131.         fDefChoice := mPopupHit;
  2132.         END
  2133.     ELSE
  2134.         BEGIN
  2135.         {$IFC qDebug}
  2136.         ProgramBreak('Attempt to use popup menus on machine that doesn''t support them');
  2137.         {$ENDC}
  2138.         fShown := False;                                { What's reasonable here ??? }
  2139.         END;
  2140.     END;
  2141.  
  2142. {--------------------------------------------------------------------------------------------------}
  2143. {$S DlgOpen}
  2144.  
  2145. PROCEDURE TPopup.IRes(itsDocument: TDocument;
  2146.                       itsSuperView: TView;
  2147.                       VAR itsParams: Ptr); OVERRIDE;
  2148.  
  2149.     VAR
  2150.         fi:                 FailInfo;
  2151.         aMenu:                MenuHandle;
  2152.  
  2153.     PROCEDURE HandleFailure(error: OSErr;
  2154.                             message: LONGINT);
  2155.  
  2156.         BEGIN
  2157.         Free;
  2158.         END;
  2159.  
  2160.     BEGIN
  2161.     fMenuHandle := NIL;
  2162.     INHERITED IRes(NIL, itsSuperView, itsParams);
  2163.  
  2164.     {$IFC NOT qNeedsHierarchicalMenus}
  2165.     IF NOT gConfiguration.hasHierarchicalMenus THEN
  2166.         BEGIN
  2167.         {$IFC qDebug}
  2168.         ProgramBreak('Attempt to use popup menus on machine that doesn''t support them');
  2169.         {$ENDC}
  2170.         fShown := False;                                { What's reasonable here ??? }
  2171.         END
  2172.     ELSE
  2173.     {$ENDC}
  2174.         BEGIN
  2175.         WITH PopupTemplatePtr(itsParams)^ DO
  2176.             BEGIN
  2177.             fCurrentItem := Max(1, currentItem);
  2178.             fItemOffset := itemOffset;
  2179.             fRsrcID := rsrcID;
  2180.             IF rsrcID <> kNoResource THEN
  2181.                 BEGIN
  2182.                 CatchFailures(fi, HandleFailure);
  2183.                 aMenu := GetMenu(rsrcID);
  2184.                 { Don't die because resource not found - just return NIL handle }
  2185.                 FailResError;
  2186.                 IF aMenu <> NIL THEN
  2187.                     HNoPurge(Handle(aMenu));
  2188.                 SetPopup(aMenu, rsrcID, fCurrentItem, False);
  2189.                 Success(fi);
  2190.                 END
  2191.             ELSE
  2192.                 fMenuID := kNoResource;
  2193.             END;
  2194.         fDefChoice := mPopupHit;
  2195.         END;
  2196.  
  2197.     OffsetPtr(itsParams, SIZEOF(PopupTemplate));
  2198.     END;
  2199.  
  2200. {--------------------------------------------------------------------------------------------------}
  2201. {$S MAWriteRes}
  2202.  
  2203. PROCEDURE TPopup.WRes(theResource: ViewRsrcHndl;
  2204.                       VAR itsParams: Ptr); OVERRIDE;
  2205.  
  2206.     VAR
  2207.         poPtr:                PopupTemplatePtr;
  2208.  
  2209.     BEGIN
  2210.     INHERITED WRes(theResource, itsParams);
  2211.  
  2212.     poPtr := PopupTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(PopupTemplate)));
  2213.  
  2214.     WITH poPtr^ DO
  2215.         BEGIN
  2216.         {$IFC qDebug}
  2217.         IF fRsrcID = kNoResource THEN
  2218.             ProgramBreak('Tried to write TPopup with no resource ID.');
  2219.         {$ENDC}
  2220.         rsrcID := fRsrcID;
  2221.         currentItem := fCurrentItem;
  2222.         itemOffset := fItemOffset;
  2223.         END;
  2224.     END;
  2225.  
  2226. {--------------------------------------------------------------------------------------------------}
  2227. {$S MAWriteRes}
  2228.  
  2229. PROCEDURE TPopup.WriteRes(theResource: ViewRsrcHndl;
  2230.                           VAR itsParams: Ptr); OVERRIDE;
  2231.  
  2232.     BEGIN
  2233.     gWResSignature := 'popp'; gWResType := 'TPopup';
  2234.     WRes(theResource, itsParams);
  2235.     END;
  2236.  
  2237. {--------------------------------------------------------------------------------------------------}
  2238. {$S DlgClose}
  2239.  
  2240. PROCEDURE TPopup.Free; OVERRIDE;
  2241.  
  2242.     BEGIN
  2243.     ReleasePopup;
  2244.  
  2245.     INHERITED Free;
  2246.     END;
  2247.  
  2248. {--------------------------------------------------------------------------------------------------}
  2249. {$S DlgOpen}
  2250.  
  2251. PROCEDURE TPopup.AdjustBotRight;
  2252.  
  2253.     VAR
  2254.         newHeight:            INTEGER;
  2255.         newWidth:            INTEGER;
  2256.         theFontInfo:        FontInfo;
  2257.  
  2258.     BEGIN
  2259.     IF fMenuHandle <> NIL THEN
  2260.         BEGIN
  2261.         CalcMenuSize(fMenuHandle);
  2262.         newWidth := fMenuHandle^^.menuWidth + fItemOffset + fInset.left + fInset.right + 3;
  2263.  
  2264.         GetTextStyleFontInfo(gSystemStyle, theFontInfo);
  2265.  
  2266.         WITH theFontInfo DO
  2267.             newHeight := ascent + descent + leading + fInset.top + fInset.bottom + 3;
  2268.  
  2269.         Resize(newWidth, newHeight, kDontInvalidate);
  2270.         END;
  2271.     END;
  2272.  
  2273. {--------------------------------------------------------------------------------------------------}
  2274. {$S DlgRes}
  2275.  
  2276. PROCEDURE TPopup.CalcLabelRect(VAR theRect: Rect);
  2277.  
  2278.     VAR
  2279.         theLabel:            Str255;
  2280.  
  2281.     BEGIN
  2282.     ControlArea(theRect);
  2283.     InsetRect(theRect, 1, 1);
  2284.     WITH theRect DO
  2285.         BEGIN
  2286.         right := left + fItemOffset - 1;                { adjust right }
  2287.         bottom := bottom - 1;                            { adjust bottom }
  2288.         theLabel := fMenuHandle^^.menuData;             { fetch the title of the menu }
  2289.         left := Max(left, right - StringWidth(theLabel) - 2); { adjust left }
  2290.         END;
  2291.     END;
  2292.  
  2293. {--------------------------------------------------------------------------------------------------}
  2294. {$S DlgRes}
  2295.  
  2296. PROCEDURE TPopup.CalcMenuRect(VAR theRect: Rect);
  2297.  
  2298.     BEGIN
  2299.     ControlArea(theRect);
  2300.     InsetRect(theRect, 1, 1);
  2301.     WITH theRect DO
  2302.         BEGIN
  2303.         left := left + fItemOffset;
  2304.         {WITH botRight DO
  2305.             BEGIN
  2306.             h := h - 1;
  2307.             v := v - 1;
  2308.             END;}
  2309.         END;
  2310.     END;
  2311.  
  2312. {--------------------------------------------------------------------------------------------------}
  2313. {$S DlgRes}
  2314.  
  2315. FUNCTION TPopup.DoMouseCommand(VAR theMouse: Point;
  2316.                                VAR info: EventInfo;
  2317.                                VAR hysteresis: Point): TCommand; OVERRIDE;
  2318.  
  2319.     VAR
  2320.         newChoice:            INTEGER;
  2321.         result:             LONGINT;
  2322.         menuPt:             Point;
  2323.         aMenuHandle:        MenuHandle;
  2324.         labelRect:            Rect;
  2325.         menuRect:            Rect;
  2326.         oldFColor:            RGBColor;
  2327.         oldBkColor:         RGBColor;
  2328.         newFColor:            RGBColor;
  2329.         newBkColor:         RGBColor;
  2330.         fi:                 FailInfo;
  2331.  
  2332.     PROCEDURE HandleFailure(error: OSErr;
  2333.                             message: LONGINT);
  2334.  
  2335.         BEGIN
  2336.         DeleteMenu(fMenuID);
  2337.         SetIfColor(oldFColor); SetIfBkColor(oldBkColor);
  2338.         END;
  2339.  
  2340.     BEGIN
  2341.     DoMouseCommand := NIL;
  2342.     CalcLabelRect(labelRect);
  2343.     CalcMenuRect(menuRect);                             { ??? test if theMouse is in menuRect ??? }
  2344.  
  2345.     IF fMenuHandle <> NIL THEN
  2346.         BEGIN
  2347.         MAInsertMenu(fMenuHandle, hierMenu);            { MAInsertMenu ensures colors are set }
  2348.         { Save the old colors, fetch the item colors, and draw the popup box }
  2349.         GetIfColor(oldFColor); GetIfBkColor(oldBkColor);
  2350.         GetMenuColors(menuRect, fMenuID, 0, newFColor, newBkColor);
  2351.         SetIfColor(newBkColor); SetIfBkColor(newFColor);
  2352.         DrawLabel(labelRect);
  2353.  
  2354.         IF (fRsrcID <> kNoResource) THEN
  2355.             IF qNeedsColorQD | gConfiguration.hasColorQD THEN
  2356.                 aMenuHandle := GetResMenu(fRsrcID);     { Reloads color tables! }
  2357.         WITH menuRect DO
  2358.             SetPt(menuPt, left, top);                     { Don't overwrite stuff next to the label }
  2359.         LocalToGlobal(menuPt);
  2360.         CalcMenuSize(fMenuHandle);                        { Fix for Menu Manager bug }
  2361.  
  2362.         SetIfColor(oldFColor); SetIfBkColor(oldBkColor);
  2363.         InsetRect(menuRect, - 1, - 1);
  2364.         EraseRect(menuRect);
  2365.  
  2366.         result := PopUpMenuSelect(fMenuHandle, menuPt.v, menuPt.h, fCurrentItem);
  2367.         newChoice := LoWord(result);
  2368.         SetIfColor(newFColor); SetIfBkColor(newBkColor);
  2369.         DrawLabel(labelRect);
  2370.         IF (HiWord(result) <> 0) & (newChoice <> fCurrentItem) THEN
  2371.             BEGIN
  2372.             SetCurrentItem(newChoice, kRedraw);
  2373.             CatchFailures(fi, HandleFailure);
  2374.             DoChoice(SELF, fDefChoice);
  2375.             Success(fi);
  2376.             END
  2377.         ELSE
  2378.             SetCurrentItem(fCurrentItem, kRedraw);
  2379.         DeleteMenu(fMenuID);
  2380.         SetIfColor(oldFColor); SetIfBkColor(oldBkColor);
  2381.         END;
  2382.     END;
  2383.  
  2384. {--------------------------------------------------------------------------------------------------}
  2385. {$S DlgRes}
  2386.  
  2387. PROCEDURE TPopup.Draw(area: Rect); OVERRIDE;
  2388.  
  2389.     VAR
  2390.         aRect:                Rect;
  2391.         oldFColor:            RGBColor;
  2392.         oldBkColor:         RGBColor;
  2393.         newFColor:            RGBColor;
  2394.         newBkColor:         RGBColor;
  2395.  
  2396.     BEGIN
  2397.     IF fMenuHandle <> NIL THEN
  2398.         BEGIN
  2399.         MAInsertMenu(fMenuHandle, hierMenu);            { MAInsertMenu ensures colors are set }
  2400.         { Erase the whole menu first }
  2401.         ControlArea(aRect);
  2402.         IF SectRect(area, aRect, aRect) THEN
  2403.             BEGIN
  2404.             { EraseRect(aRect); }
  2405.  
  2406.             { Save the old colors, fetch the item colors, and draw the popup box }
  2407.             GetIfColor(oldFColor); GetIfBkColor(oldBkColor);
  2408.             CalcMenuRect(aRect);
  2409.             GetMenuColors(aRect, fMenuID, fCurrentItem, newFColor, newBkColor);
  2410.             SetIfColor(newFColor); SetIfBkColor(newBkColor);
  2411.             DrawPopupBox(area);
  2412.  
  2413.             { Fetch the title colors, and draw it }
  2414.             GetMenuColors(aRect, fMenuID, 0, newFColor, newBkColor);
  2415.             SetIfColor(newFColor); SetIfBkColor(newBkColor);
  2416.             DrawLabel(area);
  2417.  
  2418.             { Reset colors to their original state }
  2419.             SetIfColor(oldFColor); SetIfBkColor(oldBkColor);
  2420.             END;
  2421.         DeleteMenu(fMenuID);
  2422.         END;
  2423.  
  2424.     INHERITED Draw(area);
  2425.     END;
  2426.  
  2427. {--------------------------------------------------------------------------------------------------}
  2428. {$S DlgRes}
  2429.  
  2430. PROCEDURE TPopup.DrawLabel(area: Rect);
  2431.  
  2432.     VAR
  2433.         labelRect:            Rect;
  2434.         theLabel:            Str255;
  2435.  
  2436.     BEGIN
  2437.     CalcLabelRect(labelRect);
  2438.     IF SectRect(area, labelRect, area) THEN
  2439.         BEGIN
  2440.  
  2441.         {$IFC qDebug}
  2442.         AssumeFocused;
  2443.         {$ENDC}
  2444.  
  2445.         theLabel := fMenuHandle^^.menuData;             { Fetch the title of the menu }
  2446.         IF Length(theLabel) > 0 THEN
  2447.             BEGIN
  2448.             EraseRect(labelRect);                { Might be switching colors }
  2449.             MADrawString(@theLabel, labelRect, teJustSystem);
  2450.             END;
  2451.         END;
  2452.     END;
  2453.  
  2454. {--------------------------------------------------------------------------------------------------}
  2455. {$S DlgRes}
  2456.  
  2457. PROCEDURE TPopup.DrawPopupBox(area: Rect);
  2458.  
  2459.     CONST
  2460.         ShadowedFrame        = [adnLineTop, adnLineLeft, adnLineBottom, adnLineRight, adnShadow];
  2461.         leftSlop            = 15;                        { should be 13 to image like it used to
  2462.                                                         (off by 2 pixels)  at 15 it images exactly
  2463.                                                         the same when popped up or not. }
  2464.         rightSlop            = 1;
  2465.         botSlop             = 6;
  2466.  
  2467.     VAR
  2468.         wid:                INTEGER;
  2469.         newWid:             INTEGER;
  2470.         newLen:             INTEGER;
  2471.         menuRect:            Rect;
  2472.         colorRect:            Rect;
  2473.         theItemRect:        Rect;
  2474.         theItem:            Str255;
  2475.         theFontInfo:        FontInfo;
  2476.  
  2477.     BEGIN
  2478.     CalcMenuRect(menuRect);
  2479.     GetItem(fMenuHandle, fCurrentItem, theItem);
  2480.     WITH menuRect DO
  2481.         BEGIN
  2482.         IF NOT EmptyRect(menuRect) THEN
  2483.             BEGIN
  2484.             InsetRect(menuRect, - 1, - 1);
  2485.             IF SectRect(area, menuRect, colorRect) THEN
  2486.                 BEGIN
  2487.                 wid := (right - left) - (leftSlop + rightSlop);
  2488.                 newWid := StringWidth(theItem);
  2489.                 IF newWid > wid THEN
  2490.                     BEGIN
  2491.                     newLen := Length(theItem);
  2492.  
  2493.                     REPEAT
  2494.                         theItem[newLen] := '…';
  2495.                         theItem[0] := CHR(newLen);
  2496.                         newWid := StringWidth(theItem);
  2497.                         newLen := PRED(newLen);
  2498.                     UNTIL (newWid <= wid) | (newLen = 0);
  2499.  
  2500.                     END;
  2501.  
  2502.                 PenNormal;
  2503.  
  2504.                 {$IFC qDebug}
  2505.                 AssumeFocused;
  2506.                 {$ENDC}
  2507.  
  2508.                 WITH colorRect DO
  2509.                     BEGIN
  2510.                     right := right - 1;
  2511.                     bottom := bottom - 1;
  2512.                     END;
  2513.                 EraseRect(colorRect);                    { this "paints" the background }
  2514.  
  2515.                 GetFontInfo(theFontInfo);
  2516.                 WITH theFontInfo DO
  2517.                     SetRect(theItemRect, left + leftSlop, bottom -
  2518.                             botSlop - ascent,  { top computed based on the bottom - text
  2519.                                                              height }
  2520.                             right - rightSlop, bottom - botSlop + descent);
  2521.                 MADrawString(@theItem, theItemRect, teJustSystem);
  2522.  
  2523.                 SetIfColor(gRGBBlack);
  2524.                 WITH botRight DO
  2525.                     BEGIN
  2526.                     h := h - 1;
  2527.                     v := v - 1;
  2528.                     END;
  2529.                 FrameRect(menuRect);
  2530.                 MoveTo(left + 3, bottom);
  2531.                 LineTo(right, bottom);
  2532.                 LineTo(right, top + 3);
  2533.                 END;
  2534.             END;
  2535.         END;
  2536.     END;
  2537.  
  2538. {--------------------------------------------------------------------------------------------------}
  2539. {$S DlgNonRes}
  2540.  
  2541. FUNCTION TPopup.GetCurrentItem: INTEGER;
  2542.  
  2543.     BEGIN
  2544.     GetCurrentItem := fCurrentItem;
  2545.     END;
  2546.  
  2547. {--------------------------------------------------------------------------------------------------}
  2548. {$S DlgNonRes}
  2549.  
  2550. PROCEDURE TPopup.GetItemText(item: INTEGER;
  2551.                              VAR theText: Str255);
  2552.  
  2553.     BEGIN
  2554.     IF fMenuHandle <> NIL THEN
  2555.         GetItem(fMenuHandle, item, theText)
  2556.     ELSE
  2557.         theText := '';
  2558.     END;
  2559.  
  2560. {--------------------------------------------------------------------------------------------------}
  2561. {$S DlgNonRes}
  2562.  
  2563. PROCEDURE TPopup.ReleasePopup;
  2564.  
  2565.     BEGIN
  2566.     IF fMenuHandle <> NIL THEN
  2567.         BEGIN
  2568.         HPurge(Handle(fMenuHandle));
  2569.         ReleaseResource(Handle(fMenuHandle));
  2570.         fMenuHandle := NIL;
  2571.         END;
  2572.     fMenuID := kNoResource;
  2573.     fCurrentItem := 0;
  2574.     END;
  2575.  
  2576. {--------------------------------------------------------------------------------------------------}
  2577. {$S DlgNonRes}
  2578.  
  2579. PROCEDURE TPopup.SetCurrentItem(item: INTEGER;
  2580.                                 redraw: BOOLEAN);
  2581.  
  2582.     VAR
  2583.         menuRect:            Rect;
  2584.         newFColor:            RGBColor;
  2585.         newBkColor:         RGBColor;
  2586.  
  2587.     BEGIN
  2588.     IF (fMenuHandle <> NIL) & (item <> fCurrentItem) THEN
  2589.         BEGIN
  2590.         IF fCurrentItem <> 0 THEN
  2591.             SetItemMark(fMenuHandle, fCurrentItem, ' ');
  2592.         IF item <> 0 THEN
  2593.             SetItemMark(fMenuHandle, item, CHR(checkMark));
  2594.         fCurrentItem := item;
  2595.         END;
  2596.     IF redraw & Focus & IsVisible THEN
  2597.         BEGIN
  2598.         GetQDExtent(menuRect);
  2599.         GetMenuColors(menuRect, fMenuID, item, newFColor, newBkColor);
  2600.         SetIfColor(newFColor); SetIfBkColor(newBkColor);
  2601.         DrawPopupBox(menuRect);
  2602.         END;
  2603.     END;
  2604.  
  2605. {--------------------------------------------------------------------------------------------------}
  2606. {$S DlgRes}
  2607.  
  2608. PROCEDURE TPopup.SetPopup(theMenu: MenuHandle;
  2609.                           theRsrcID, currentItem: INTEGER;
  2610.                           redraw: BOOLEAN);
  2611.  
  2612.     VAR
  2613.         fi:                 FailInfo;
  2614.  
  2615.     PROCEDURE HandleFailure(error: OSErr;
  2616.                             message: LONGINT);
  2617.  
  2618.         BEGIN
  2619.         Free;
  2620.         END;
  2621.  
  2622.     BEGIN
  2623.     ReleasePopup;
  2624.     IF theMenu <> NIL THEN
  2625.         BEGIN
  2626.         IF theRsrcID <> kNoResource THEN
  2627.             BEGIN
  2628.             CatchFailures(fi, HandleFailure);
  2629.             DetachResource(Handle(theMenu));
  2630.             FailResError;
  2631.             Success(fi);
  2632.             END;
  2633.         fMenuHandle := theMenu;
  2634.         fMenuID := theMenu^^.menuID;
  2635.         END;
  2636.     fRsrcID := theRsrcID;
  2637.     SetCurrentItem(Max(1, currentItem), kDontRedraw);
  2638.     AdjustBotRight;
  2639.     IF redraw THEN
  2640.         ForceRedraw;
  2641.     END;
  2642.  
  2643. {--------------------------------------------------------------------------------------------------}
  2644. {$S DlgFields}
  2645.  
  2646. PROCEDURE TPopup.Fields(PROCEDURE DoToField(fieldName: Str255;
  2647.                                             fieldAddr: Ptr;
  2648.                                             fieldType: INTEGER)); OVERRIDE;
  2649.  
  2650.     BEGIN
  2651.     DoToField('TPopup', NIL, bClass);
  2652.     DoToField('fRsrcID', @fRsrcID, bInteger);
  2653.     DoToField('fMenuID', @fMenuID, bInteger);
  2654.     DoToField('fMenuHandle', @fMenuHandle, bHandle);
  2655.     DoToField('fCurrentItem', @fCurrentItem, bInteger);
  2656.     DoToField('fItemOffset', @fItemOffset, bInteger);
  2657.  
  2658.     INHERITED Fields(DoToField);
  2659.     END;
  2660.  
  2661. {--------------------------------------------------------------------------------------------------}
  2662. {$S TEOpen}
  2663.  
  2664. PROCEDURE TDialogTEView.IDialogTEView(itsDocument: TDocument; itsSuperView: TView; itsLocation,
  2665.                                       itsSize: VPoint; itsHDeterminer,
  2666.                                       itsVDeterminer: SizeDeterminer; itsInset: Rect;
  2667.                                       itsTextStyle: TextStyle; itsJustification: INTEGER;
  2668.                                       itsStyleType, itsAutoWrap: BOOLEAN);
  2669.  
  2670.     BEGIN
  2671.     fEditText := NIL; { We don't own this reference but we don't want an invalid one either }
  2672.     fScroller := NIL;
  2673.  
  2674.     ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer,
  2675.             itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
  2676.  
  2677.     fScroller := MakeScroller;
  2678.     IF fScroller <> NIL THEN
  2679.         fScroller.AddSubView(SELF);
  2680.     END;
  2681.  
  2682. {--------------------------------------------------------------------------------------------------}
  2683. {$S TEOpen}
  2684.  
  2685. PROCEDURE TDialogTEView.IRes(itsDocument: TDocument;
  2686.                              itsSuperView: TView;
  2687.                              VAR itsParams: Ptr); OVERRIDE;
  2688.  
  2689.  
  2690.     BEGIN
  2691.     fEditText := NIL;                                    { We don't own this reference but we don't
  2692.                                                          want an invalid one either }
  2693.     fScroller := NIL;
  2694.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  2695.  
  2696.     fScroller := MakeScroller;
  2697.     IF fScroller <> NIL THEN
  2698.         fScroller.AddSubView(SELF);
  2699.     END;
  2700.  
  2701. {--------------------------------------------------------------------------------------------------}
  2702. {$S TEClose}
  2703.  
  2704. PROCEDURE TDialogTEView.Free; OVERRIDE;
  2705.  
  2706.  
  2707.     BEGIN
  2708.     if fScroller <> NIL THEN
  2709.         BEGIN
  2710.         fScroller.RemoveSubView(SELF);
  2711.         FreeIfObject(fScroller);
  2712.         fScroller := NIL;
  2713.         END;
  2714.  
  2715.     INHERITED Free;
  2716.     END;
  2717.  
  2718. {--------------------------------------------------------------------------------------------------}
  2719. {$S DlgFields}
  2720.  
  2721. PROCEDURE TDialogTEView.Fields(PROCEDURE DoToField(fieldName: Str255;
  2722.                                                    fieldAddr: Ptr;
  2723.                                                    fieldType: INTEGER)); OVERRIDE;
  2724.  
  2725.     BEGIN
  2726.     DoToField('TDialogTEView', NIL, bClass);
  2727.     DoToField('fEditText', @fEditText, bObject);
  2728.     DoToField('fScroller', @fScroller, bObject);
  2729.  
  2730.     INHERITED Fields(DoToField);
  2731.     END;
  2732.  
  2733. {--------------------------------------------------------------------------------------------------}
  2734. {$S DlgNonRes}
  2735.  
  2736. PROCEDURE TDialogTEView.InstallEditText(theEditText: TEditText;
  2737.                                         selectChars: BOOLEAN);
  2738.  
  2739.     VAR
  2740.         theText:            Str255;
  2741.         aTextStyle:         TextStyle;
  2742.         theControlArea:     Rect;
  2743.         validExtent:        VRect;
  2744.         hadPendingUpdate:    Boolean;
  2745.  
  2746.     BEGIN
  2747.     IF fEditText <> NIL THEN
  2748.         BEGIN
  2749.         fEditText.RemoveSubView(fScroller);
  2750.         fEditText := NIL;
  2751.         END;
  2752.  
  2753.     IF theEditText <> NIL THEN
  2754.         BEGIN
  2755.         fControlChars := theEditText.fControlChars;
  2756.         fMaxChars := theEditText.fMaxChars;
  2757.         fInset := gZeroRect;
  2758.         hadPendingUpdate := theEditText.HasPendingUpdate;
  2759.  
  2760.         SetJustification(theEditText.fJust, kDontRedraw);
  2761.         ChangeWrap(theEditText.fAutoWrap, kDontRedraw);
  2762.  
  2763.         aTextStyle := theEditText.fTextStyle;
  2764.         SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
  2765.  
  2766.         theEditText.ControlArea(theControlArea);
  2767.  
  2768.         theEditText.AddSubView(fScroller);{ my scroller }
  2769.  
  2770.         IF fAutoWrap THEN
  2771.             fSizeDeterminer[h] := sizeSuperView
  2772.         ELSE
  2773.             fSizeDeterminer[h] := sizeVariable;    { Let the width vary with the number of characters }
  2774.  
  2775.         WITH theControlArea DO
  2776.             BEGIN
  2777.             fSuperView.Resize(right - left, bottom - top, kDontInvalidate);
  2778.             fSuperView.Locate(left, top, kDontInvalidate);
  2779.             END;
  2780.  
  2781.         theEditText.GetText(theText);
  2782.         SetText(theText);
  2783.         RecalcText;
  2784.         SynchView(kDontRedraw);
  2785.         AdjustSize;
  2786.  
  2787.     { Make the scroller's thinking match the display that the user already sees }
  2788.         fScroller.fTranslation.h := 0;
  2789.         CASE GetActualJustification(fJustification) OF
  2790.             teJustLeft, teForceLeft:
  2791.                 fScroller.fTranslation.v := 0;
  2792.             teJustRight:    { Right brain thinkers… left brain thinkers?? }
  2793.                 TScroller(fSuperView).fTranslation.h := fScroller.fMaxTranslation.h;
  2794.             teJustCenter:
  2795.                 fScroller.fTranslation.h := fScroller.fMaxTranslation.h DIV 2;
  2796.             END;
  2797.         theEditText.InvalidateFocus;
  2798.  
  2799.         IF selectChars THEN
  2800.             SetSelect(0, MAXINT, fHTE)
  2801.         ELSE
  2802.             SetSelect(0, 0, fHTE);                        { Caller will set the selection. }
  2803.  
  2804.         BeInScroller(fScroller);
  2805.  
  2806.     { Make my enable and my scroller's enable match my new superview }
  2807.     ViewEnable(theEditText.IsViewEnabled, kDontRedraw);
  2808.     fScroller.ViewEnable(theEditText.IsViewEnabled, kDontRedraw);
  2809.     fScroller.fRespondsToFunctionKeys := FALSE;            { !!! need a better way to let enclosing
  2810.                                                         dialog scroll by function keys if necessary }
  2811.  
  2812.     { Revalidate my extent to eliminate the flicker created by resizing the scrollers }
  2813.         IF NOT hadPendingUpdate & Focus THEN
  2814.             BEGIN
  2815.             GetExtent(validExtent);
  2816.             ValidVRect(validExtent);
  2817.             END;
  2818.         END;
  2819.  
  2820.     fEditText := theEditText;
  2821.     END;
  2822.  
  2823. {--------------------------------------------------------------------------------------------------}
  2824. {$S DlgNonRes}
  2825.  
  2826. PROCEDURE TDialogTEView.InstallSelection(wasActive, beActive: BOOLEAN); OVERRIDE;
  2827.  
  2828.     BEGIN
  2829.  { If we're deselecting a field and it's been scrolled, invalidate it
  2830.   so that it is redrawn correctly.}
  2831.     IF NOT beActive THEN
  2832.         IF fScroller.fTranslation.v <> 0 THEN
  2833.             ForceRedraw
  2834.         ELSE
  2835.             CASE GetActualJustification(fJustification) OF
  2836.                 teJustLeft, teForceLeft:
  2837.                     BEGIN
  2838.                     IF fScroller.fTranslation.h <> 0 THEN
  2839.                         ForceRedraw;
  2840.                     END;
  2841.                 teJustRight:
  2842.                     BEGIN
  2843.                     IF fScroller.fTranslation.h <> fScroller.fMaxTranslation.h THEN
  2844.                         ForceRedraw;
  2845.                     END;
  2846.                 teJustCenter:
  2847.                     BEGIN
  2848.                     IF fScroller.fTranslation.h <> (fScroller.fMaxTranslation.h DIV 2) THEN
  2849.                         ForceRedraw;
  2850.                     END;
  2851.             END;
  2852.  
  2853.     INHERITED InstallSelection(wasActive, beActive);
  2854.     END;
  2855.  
  2856. {--------------------------------------------------------------------------------------------------}
  2857. {$S DlgNonRes}
  2858.  
  2859. PROCEDURE TDialogTEView.ComputeSize(VAR newSize: VPoint); OVERRIDE;
  2860.  
  2861.     BEGIN
  2862.     INHERITED ComputeSize(newSize);
  2863.     
  2864.     IF NOT fAutoWrap  THEN
  2865.         CASE fSizeDeterminer[h] OF
  2866.             sizeVariable:
  2867.                 { TTEView already computed the variable size, bump it up to at leat the scroller's
  2868.                 size so that the cursor is claimed for the EditText and the user can click anywhere. }
  2869.                 IF NOT fStyleType THEN
  2870.                     newSize.h := Max(fScroller.fSize.h, newSize.h);
  2871.         END;
  2872.     END;
  2873.  
  2874. {--------------------------------------------------------------------------------------------------}
  2875. {$S TEOpen}
  2876.  
  2877. FUNCTION TDialogTEView.MakeScroller: TScroller;
  2878. { Must return a scroller.  !!! enhance the TDialogTEView to be able to function without a scroller }
  2879.     VAR
  2880.         aScroller: TScroller;
  2881.  
  2882.     BEGIN
  2883.     aScroller := NIL;
  2884.     New(aScroller);
  2885.     FailNil(aScroller);
  2886.     aScroller.IScroller(NIL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, 0, 0,
  2887.                         NOT kWantHScrollBar, NOT kWantVScrollBar);
  2888.     MakeScroller := aScroller;
  2889.     END;
  2890.  
  2891. {--------------------------------------------------------------------------------------------------}
  2892. {$S DlgOpen}
  2893.  
  2894. PROCEDURE TStaticText.IStaticText(itsSuperView: TView;
  2895.                                   itsLocation, itsSize: VPoint;
  2896.                                   itsHSizeDet, itsVSizeDet: SizeDeterminer;
  2897.                                   itsRsrcID, itsIndex: INTEGER);
  2898.  
  2899.     VAR
  2900.         aString:            Str255;
  2901.         fi:                 FailInfo;
  2902.  
  2903.     PROCEDURE HandleFailure(error: OSErr;
  2904.                             message: LONGINT);
  2905.  
  2906.         BEGIN
  2907.         Free;
  2908.         END;
  2909.  
  2910.     BEGIN
  2911.     fDataHandle := NIL;
  2912.     IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
  2913.     fRsrcID := itsRsrcID;
  2914.     fIndex := itsIndex;
  2915.     fJust := teJustSystem;                                { Default to system justification }
  2916.     fAutoWrap := TRUE;                                    { Default to compatibility with 2.0 }
  2917.     IF fRsrcID <> kNoResource THEN
  2918.         BEGIN
  2919.         CatchFailures(fi, HandleFailure);
  2920.         GetIndString(aString, fRsrcID, fIndex);
  2921.         FailResError;
  2922.         Success(fi);
  2923.         SetText(aString, kDontRedraw);
  2924.         END;
  2925.     ViewEnable(False, kDontRedraw);                     { Default is to not enable hit testing }
  2926.     fDefChoice := mStaticTextHit;
  2927.     END;
  2928.  
  2929. {--------------------------------------------------------------------------------------------------}
  2930. {$S DlgOpen}
  2931.  
  2932. PROCEDURE TStaticText.IRes(itsDocument: TDocument;
  2933.                            itsSuperView: TView;
  2934.                            VAR itsParams: Ptr); OVERRIDE;
  2935.  
  2936.     BEGIN
  2937.     fRsrcID := kNoResource;
  2938.     fIndex := 0;
  2939.     fDataHandle := NIL;
  2940.     INHERITED IRes(NIL, itsSuperView, itsParams);
  2941.  
  2942.     fAutoWrap := TRUE;                                    { Default to compatibility with 2.0 }
  2943.     fDefChoice := mStaticTextHit;
  2944.     WITH StaticTextTemplatePtr(itsParams)^ DO
  2945.         BEGIN
  2946.         fJust := just;
  2947.         SetText(data, kDontRedraw);
  2948.         END;
  2949.  
  2950.     OffsetPtrWStr(itsParams, SIZEOF(StaticTextTemplate));
  2951.     END;
  2952.  
  2953. {--------------------------------------------------------------------------------------------------}
  2954. {$S MAWriteRes}
  2955.  
  2956. PROCEDURE TStaticText.WRes(theResource: ViewRsrcHndl;
  2957.                            VAR itsParams: Ptr); OVERRIDE;
  2958.  
  2959.     VAR
  2960.         theText:            Str255;
  2961.         stPtr:                StaticTextTemplatePtr;
  2962.  
  2963.     BEGIN
  2964.     INHERITED WRes(theResource, itsParams);
  2965.  
  2966.     GetText(theText);
  2967.  
  2968.     stPtr := StaticTextTemplatePtr(ExpandPtrWStr(theResource, itsParams, SIZEOF(StaticTextTemplate),
  2969.                                                  Length(theText)));
  2970.  
  2971.     WITH stPtr^ DO
  2972.         BEGIN
  2973.         just := fJust;
  2974.         { data := theText; }
  2975.         CopyStr255(theText, PRStr(data));
  2976.         END;
  2977.     END;
  2978.  
  2979. {--------------------------------------------------------------------------------------------------}
  2980. {$S MAWriteRes}
  2981.  
  2982. PROCEDURE TStaticText.WriteRes(theResource: ViewRsrcHndl;
  2983.                                VAR itsParams: Ptr); OVERRIDE;
  2984.  
  2985.     BEGIN
  2986.     gWResSignature := 'stat'; gWResType := 'TStaticText';
  2987.     WRes(theResource, itsParams);
  2988.     END;
  2989.  
  2990. {--------------------------------------------------------------------------------------------------}
  2991. {$S DlgClose}
  2992.  
  2993. PROCEDURE TStaticText.Free; OVERRIDE;
  2994.  
  2995.     BEGIN
  2996.     ReleaseText;
  2997.  
  2998.     INHERITED Free;
  2999.     END;
  3000.  
  3001. {--------------------------------------------------------------------------------------------------}
  3002. {$S DlgRes}
  3003.  
  3004. PROCEDURE TStaticText.ChangeWrap(newAutoWrap, redraw: BOOLEAN);
  3005.  
  3006.     BEGIN
  3007.     fAutoWrap := newAutoWrap;
  3008.     IF Redraw THEN
  3009.         ForceRedraw;
  3010.     END;
  3011.  
  3012. {--------------------------------------------------------------------------------------------------}
  3013. {$S DlgRes}
  3014.  
  3015. PROCEDURE TStaticText.DoSubstitution(VAR theText: Str255);
  3016.  
  3017.     VAR
  3018.         aDialogView:        TDialogView;
  3019.  
  3020.     BEGIN
  3021.     aDialogView := TDialogView(GetDialogView);
  3022.     IF aDialogView <> NIL THEN
  3023.         aDialogView.ReplaceText(theText);
  3024.     END;
  3025.  
  3026. {--------------------------------------------------------------------------------------------------}
  3027. {$S DlgRes}
  3028.  
  3029. PROCEDURE TStaticText.Draw(area: Rect); OVERRIDE;
  3030.  
  3031.     VAR
  3032.         theRect:            Rect;
  3033.         oldColor:            RGBColor;
  3034.         theText:            Str255;
  3035.         aTextStyle:         TextStyle;
  3036.  
  3037.     BEGIN
  3038.     IF fDataHandle <> NIL THEN
  3039.         BEGIN
  3040.         GetText(theText);
  3041.         DoSubstitution(theText);                        { Make the substitution if desired }
  3042.         ControlArea(theRect);
  3043.         PenNormal;                                        { ??? NECESSARY ??? }
  3044.         GetIfColor(oldColor);
  3045.         aTextStyle := fTextStyle;
  3046.         SetPortTextStyle(aTextStyle);
  3047.         ImageText(Ptr(ORD4(@theText) + 1), Length(theText), theRect, fJust);
  3048.         SetIfColor(oldColor);
  3049.         END;
  3050.     INHERITED Draw(area);
  3051.     END;
  3052.  
  3053. {--------------------------------------------------------------------------------------------------}
  3054. {$S DlgRes}
  3055.  
  3056. PROCEDURE TStaticText.GetText(VAR theText: Str255);
  3057.  
  3058.     BEGIN
  3059.     IF fDataHandle <> NIL THEN
  3060.     { theText := fDataHandle^^ }
  3061.         CopyStr255(fDataHandle^^, @theText)
  3062.     ELSE
  3063.         theText := '';
  3064.     END;
  3065.  
  3066. {--------------------------------------------------------------------------------------------------}
  3067. {$S DlgRes}
  3068.  
  3069. PROCEDURE TStaticText.ImageText(text: Ptr;
  3070.                                 Length: LONGINT;
  3071.                                 box: Rect;
  3072.                                 just: INTEGER);
  3073.  
  3074.     BEGIN
  3075.     MATextBox(text, Length, box, just, fAutoWrap, NIL, kNoEraseFirst, kSpaceForCaret);
  3076.     END;
  3077.  
  3078. {--------------------------------------------------------------------------------------------------}
  3079. {$S DlgNonRes}
  3080.  
  3081. PROCEDURE TStaticText.ReleaseText;
  3082.  
  3083.     BEGIN
  3084.     Handle(fDataHandle) := DisposeIfHandle(fDataHandle);
  3085.  
  3086.     fRsrcID := kNoResource;
  3087.     END;
  3088.  
  3089. {--------------------------------------------------------------------------------------------------}
  3090. {$S DlgNonRes}
  3091.  
  3092. PROCEDURE TStaticText.SetJustification(theJust: INTEGER;
  3093.                                        redraw: BOOLEAN);
  3094.  
  3095.     BEGIN
  3096.     fJust := theJust;
  3097.     IF redraw THEN
  3098.         ForceRedraw;
  3099.     END;
  3100.  
  3101. {--------------------------------------------------------------------------------------------------}
  3102. {$S DlgNonRes}
  3103.  
  3104. PROCEDURE TStaticText.SetText(theText: Str255;
  3105.                               redraw: BOOLEAN);
  3106.  
  3107.     VAR
  3108.         area:                Rect;
  3109.  
  3110.     BEGIN
  3111.     IF (fDataHandle = NIL) | (theText <> fDataHandle^^) THEN
  3112.         BEGIN
  3113.         ReleaseText;
  3114.         fDataHandle := NewString(theText);
  3115.         IF MemError <> noErr THEN
  3116.             fDataHandle := NIL;
  3117.         IF redraw & Focus & IsVisible THEN
  3118.             BEGIN
  3119.             ControlArea(area);
  3120.             EraseRect(area);
  3121.             Draw(area);
  3122.             END;
  3123.         END;
  3124.     END;
  3125.  
  3126. {--------------------------------------------------------------------------------------------------}
  3127. {$S DlgFields}
  3128.  
  3129. PROCEDURE TStaticText.Fields(PROCEDURE DoToField(fieldName: Str255;
  3130.                                                  fieldAddr: Ptr;
  3131.                                                  fieldType: INTEGER)); OVERRIDE;
  3132.  
  3133.     VAR
  3134.         aString:            Str255;
  3135.  
  3136.     BEGIN
  3137.     DoToField('TStaticText', NIL, bClass);
  3138.     DoToField('fRsrcID', @fRsrcID, bInteger);
  3139.     DoToField('fIndex', @fIndex, bInteger);
  3140.     DoToField('fDataHandle', @fDataHandle, bHandle);
  3141.     IF fDataHandle <> NIL THEN
  3142.         BEGIN
  3143.         aString := fDataHandle^^;
  3144.         DoToField('fDataHandle^^', @aString, bString);
  3145.         END;
  3146.     DoToField('fJust', @fJust, bInteger);
  3147.     DoToField('fAutoWrap', @fAutoWrap, bBoolean);
  3148.  
  3149.     INHERITED Fields(DoToField);
  3150.     END;
  3151.  
  3152. {--------------------------------------------------------------------------------------------------}
  3153. {$S DlgOpen}
  3154.  
  3155. PROCEDURE TEditText.IEditText(itsSuperView: TView;
  3156.                               itsLocation, itsSize: VPoint;
  3157.                               itsMaxChars: INTEGER);
  3158.  
  3159.     BEGIN
  3160.     fTEView := NIL;
  3161.     IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
  3162.  
  3163.     fAutoWrap := FALSE;                                    { Default to compatibility with 2.0
  3164.                                                         Never the twain shall meet.}
  3165.     fMaxChars := itsMaxChars;
  3166.     fControlChars := [chLeft, chRight, chUp, chDown, chBackspace];
  3167.     fTextStyle := gSystemStyle;
  3168.     Inset(3, 3, kDontRedraw);                            { Default is a little, teeny inset… }
  3169.     fPenSize := Point($00010001);                        { …and a thin frame }
  3170.     fAdornment := kFrame;
  3171.     ViewEnable(TRUE, kDontRedraw);
  3172.     fDefChoice := mEditTextHit;
  3173.     END;
  3174.  
  3175. {--------------------------------------------------------------------------------------------------}
  3176. {$S DlgOpen}
  3177.  
  3178. PROCEDURE TEditText.IRes(itsDocument: TDocument;
  3179.                          itsSuperView: TView;
  3180.                          VAR itsParams: Ptr); OVERRIDE;
  3181.  
  3182.     BEGIN
  3183.     fTEView := NIL;
  3184.     INHERITED IRes(NIL, itsSuperView, itsParams);
  3185.  
  3186.     fAutoWrap := FALSE;                                    { Default to compatibility with 2.0
  3187.                                                         Never the twain shall meet.}
  3188.     WITH EditTextTemplatePtr(itsParams)^ DO
  3189.         BEGIN
  3190.         fMaxChars := maxChars;
  3191.         fControlChars := controlChars;
  3192.         END;
  3193.     fDefChoice := mEditTextHit;
  3194.  
  3195.     OffsetPtr(itsParams, SIZEOF(EditTextTemplate));
  3196.     END;
  3197.  
  3198. {--------------------------------------------------------------------------------------------------}
  3199. {$S DlgClose}
  3200.  
  3201. PROCEDURE TEditText.Free; OVERRIDE;
  3202.  
  3203.     BEGIN
  3204.     IF fTEView <> NIL THEN
  3205.         BEGIN
  3206.         fTEView.InstallEditText(NIL, False);
  3207.         fTEView := NIL
  3208.         END;
  3209.  
  3210.     INHERITED Free;
  3211.     END;
  3212.  
  3213. {--------------------------------------------------------------------------------------------------}
  3214. {$S MAWriteRes}
  3215.  
  3216. PROCEDURE TEditText.WRes(theResource: ViewRsrcHndl;
  3217.                          VAR itsParams: Ptr); OVERRIDE;
  3218.  
  3219.     VAR
  3220.         edPtr:                EditTextTemplatePtr;
  3221.  
  3222.     BEGIN
  3223.     INHERITED WRes(theResource, itsParams);
  3224.  
  3225.     edPtr := EditTextTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(EditTextTemplate)));
  3226.  
  3227.     WITH edPtr^ DO
  3228.         BEGIN
  3229.         maxChars := fMaxChars;
  3230.         controlChars := fControlChars;
  3231.         END;
  3232.     END;
  3233.  
  3234. {--------------------------------------------------------------------------------------------------}
  3235. {$S MAWriteRes}
  3236.  
  3237. PROCEDURE TEditText.WriteRes(theResource: ViewRsrcHndl;
  3238.                              VAR itsParams: Ptr); OVERRIDE;
  3239.  
  3240.     BEGIN
  3241.     gWResSignature := 'edit'; gWResType := 'TEditText';
  3242.     WRes(theResource, itsParams);
  3243.     END;
  3244.  
  3245. {--------------------------------------------------------------------------------------------------}
  3246. {$S DlgRes}
  3247.  
  3248. PROCEDURE TEditText.ChangeWrap(newAutoWrap, redraw: BOOLEAN); OVERRIDE;
  3249.  
  3250.     BEGIN
  3251.     INHERITED ChangeWrap(newAutoWrap, redraw);
  3252.     IF fTEView <> NIL THEN
  3253.         fTEView.ChangeWrap(newAutoWrap, redraw)
  3254.     END;
  3255.  
  3256. {--------------------------------------------------------------------------------------------------}
  3257. {$S DlgRes}
  3258.  
  3259. FUNCTION TEditText.HandleMouseDown(theMouse: VPoint;
  3260.                                VAR info: EventInfo;
  3261.                                VAR hysteresis: Point;
  3262.                                VAR theCommand: TCommand): BOOLEAN; OVERRIDE;
  3263.  
  3264.     BEGIN
  3265.     IF (gTarget <> fTEView) THEN    { Get the floating TE installed if necessary }
  3266.         DoChoice(SELF, fDefChoice);
  3267.  
  3268.     HandleMouseDown := INHERITED HandleMouseDown(theMouse, info, hysteresis, theCommand);
  3269.     END;
  3270.  
  3271. {--------------------------------------------------------------------------------------------------}
  3272. {$S DlgRes}
  3273.  
  3274. PROCEDURE TEditText.DoSubstitution(VAR theText: Str255); OVERRIDE;
  3275.  
  3276.     BEGIN
  3277.     { Default action is for editable text items is not to do any substitions }
  3278.     END;
  3279.  
  3280. {--------------------------------------------------------------------------------------------------}
  3281. {$S DlgRes}
  3282.  
  3283. PROCEDURE TEditText.Draw(area: Rect); OVERRIDE;
  3284.  
  3285.     VAR
  3286.         theRect:            Rect;
  3287.  
  3288.     BEGIN
  3289.     IF fTEView <> NIL THEN
  3290.         BEGIN
  3291.         GetQDExtent(theRect);
  3292.         Adorn(theRect, fPenSize, fAdornment);
  3293.         END
  3294.     ELSE
  3295.         INHERITED Draw(area);
  3296.     END;
  3297.  
  3298. {--------------------------------------------------------------------------------------------------}
  3299. {$S DlgFields}
  3300.  
  3301. PROCEDURE TEditText.Fields(PROCEDURE DoToField(fieldName: Str255;
  3302.                                                fieldAddr: Ptr;
  3303.                                                fieldType: INTEGER)); OVERRIDE;
  3304.  
  3305.     BEGIN
  3306.     DoToField('TEditText', NIL, bClass);
  3307.     DoToField('fMaxChars', @fMaxChars, bInteger);
  3308.     DoToField('fTEView', @fTEView, bObject);
  3309.     DoToField('fControlChars', @fControlChars, bHexLongInt);
  3310.  
  3311.     INHERITED Fields(DoToField);
  3312.     END;
  3313.  
  3314. {--------------------------------------------------------------------------------------------------}
  3315. {$S DlgRes}
  3316.  
  3317. PROCEDURE TEditText.GetText(VAR theText: Str255); OVERRIDE;
  3318.  
  3319.     VAR
  3320.         theChars:            Handle;
  3321.         numberOfChars:        INTEGER;
  3322.  
  3323.     BEGIN
  3324.     IF fTEView = NIL THEN
  3325.         INHERITED GetText(theText)
  3326.     ELSE
  3327.         BEGIN
  3328.         theChars := fTEView.ExtractText;
  3329.         numberOfChars := MIN(255, GetHandleSize(theChars));
  3330.         {$Push} {$R-}
  3331.         theText[0] := CHR(numberOfChars);
  3332.         {$Pop}
  3333.         BlockMove(Ptr(theChars^), Ptr(ORD4(@theText) + 1), numberOfChars);
  3334.         END;
  3335.     END;
  3336.  
  3337. {--------------------------------------------------------------------------------------------------}
  3338.  
  3339. PROCEDURE TEditText.ImageText(text: Ptr;
  3340.                               Length: LONGINT;
  3341.                               box: Rect;
  3342.                               just: INTEGER); OVERRIDE;
  3343.  
  3344.     BEGIN
  3345.     IF Length >= 0 THEN
  3346.         MATextBox(text, Length, box, just, fAutoWrap , NIL, kNoEraseFirst,
  3347.         kSpaceForCaret);
  3348.     END;
  3349.  
  3350. {--------------------------------------------------------------------------------------------------}
  3351. {$S DlgNonRes}
  3352.  
  3353. PROCEDURE TEditText.RestartEdit(restartText: Str255);
  3354.  
  3355.     VAR
  3356.         area:                Rect;
  3357.  
  3358.     BEGIN
  3359.     IF fTEView.Focus THEN                                { First, attempt to focus the TEView }
  3360.         BEGIN
  3361.         ClipRect(gZeroRect);                            { Prevent TE from mucking up the hilite with
  3362.                                                          a stinking insertion point }
  3363.  
  3364.         InstallSelection(TRUE, False);                    { Deactivate the selection }
  3365.         SetText(restartText, kDontRedraw);                { Set the text to previous value }
  3366.         SetSelection(0, MAXINT, kDontRedraw);            { Select all characters }
  3367.  
  3368.         InstallSelection(False, TRUE);                    { Activate the selection }
  3369.         InvalidateFocus;                                { Make sure we re-focus }
  3370.         fTEView.ForceRedraw;
  3371.         END
  3372.     ELSE
  3373.         SetText(restartText, kDontRedraw);                { Just set the text if we can't focus }
  3374.     END;
  3375.  
  3376. {--------------------------------------------------------------------------------------------------}
  3377. {$S DlgNonRes}
  3378.  
  3379. PROCEDURE TEditText.SetJustification(theJust: INTEGER;
  3380.                                      redraw: BOOLEAN);
  3381.  
  3382.     BEGIN
  3383.     IF fTEView <> NIL THEN
  3384.         fTEView.SetJustification(theJust, redraw);
  3385.     INHERITED SetJustification(theJust, redraw);
  3386.     END;
  3387.  
  3388. {--------------------------------------------------------------------------------------------------}
  3389. {$S DlgRes}
  3390.  
  3391. PROCEDURE TEditText.SetSelection(selStart, selEnd: INTEGER;
  3392.                                  redraw: BOOLEAN);
  3393.  
  3394.     BEGIN
  3395.     IF fTEView <> NIL THEN
  3396.         BEGIN
  3397.         IF redraw & fTEView.Focus & fTEView.IsVisible THEN
  3398.             BEGIN
  3399.             TESetSelect(selStart, selEnd, fTEView.fHTE);
  3400.             END
  3401.         ELSE
  3402.             SetSelect(selStart, selEnd, fTEView.fHTE);
  3403.         END;
  3404.     END;
  3405.  
  3406. {--------------------------------------------------------------------------------------------------}
  3407. {$S DlgNonRes}
  3408.  
  3409. PROCEDURE TEditText.SetText(theText: Str255;
  3410.                             redraw: BOOLEAN); OVERRIDE;
  3411.  
  3412.     VAR
  3413.         currentText:        Str255;
  3414.         area:                Rect;
  3415.  
  3416.     BEGIN
  3417.     IF fTEView <> NIL THEN
  3418.         BEGIN
  3419.         GetText(currentText);
  3420.         IF currentText <> theText THEN
  3421.             BEGIN
  3422.             fTEView.SetText(theText);
  3423.             fTEView.RecalcText;
  3424.             fTEView.SynchView(kDontRedraw);
  3425.             IF redraw & Focus & IsVisible THEN
  3426.                 BEGIN
  3427.                 ControlArea(area);
  3428.                 EraseRect(area);
  3429.                 DrawContents;
  3430.                 END;
  3431.             END;
  3432.         END
  3433.     ELSE
  3434.         INHERITED SetText(theText, redraw);
  3435.     END;
  3436.  
  3437. {--------------------------------------------------------------------------------------------------}
  3438. {$S DlgRes}
  3439.  
  3440. PROCEDURE TEditText.InstallSelection(wasActive, beActive: BOOLEAN); OVERRIDE;
  3441.  
  3442.     BEGIN
  3443.     IF fTEView <> NIL THEN
  3444.         fTEView.InstallSelection(wasActive, beActive);
  3445.     END;
  3446.  
  3447. {--------------------------------------------------------------------------------------------------}
  3448. {$S DlgNonRes}
  3449.  
  3450. PROCEDURE TEditText.StartEdit(selectChars: BOOLEAN;
  3451.                               theTEView: TDialogTEView);
  3452.  
  3453.     VAR
  3454.         myExtent:            VRect;
  3455.         minToSee:            Point;
  3456.         itsWindow:            TWindow;
  3457.  
  3458.     BEGIN
  3459.     IF theTEView = NIL THEN
  3460.         BEGIN
  3461.         {$IFC qDebug}
  3462.         ProgramBreak('the TEView is nil.');
  3463.         {$ENDC}
  3464.         EXIT(StartEdit);
  3465.         END;
  3466.  
  3467.     theTEView.InstallEditText(SELF, selectChars);
  3468.     fTEView := theTEView;
  3469.     itsWindow := GetWindow;                             { Set the window's target, which sets }
  3470.     IF itsWindow <> NIL THEN                            { …the application's target if it is }
  3471.         itsWindow.SetTarget(theTEView);                 { …the front window. }
  3472.  
  3473.     GetExtent(myExtent);
  3474.     InsetVRect(myExtent, - 10, - 10);
  3475.     minToSee.h := MIN(fSize.h + 10, kMaxCoord);
  3476.     minToSee.v := MIN(fSize.v + 10, kMaxCoord);
  3477.  
  3478.     RevealRect(myExtent, minToSee, kVisible);            { Make me visible }
  3479.     END;
  3480.  
  3481. {--------------------------------------------------------------------------------------------------}
  3482. {$S DlgNonRes}
  3483.  
  3484. PROCEDURE TEditText.StopEdit;
  3485.  
  3486.     VAR
  3487.         aString:            Str255;
  3488.  
  3489.     BEGIN
  3490.     IF fTEView <> NIL THEN
  3491.         BEGIN
  3492.         GetText(aString);                                { Must get the text before calling
  3493.                                                          InstallEditText }
  3494.         fTEView.InstallSelection(TRUE, False);
  3495.         fTEView.InstallEditText(NIL, False);
  3496.         fTEView := NIL;
  3497.         SetText(aString, kDontRedraw);
  3498.         END;
  3499.     END;
  3500.  
  3501. {--------------------------------------------------------------------------------------------------}
  3502. {$S DlgRes}
  3503.  
  3504. FUNCTION TEditText.Validate: LONGINT;
  3505.  
  3506.     VAR
  3507.         validateResult:     LONGINT;
  3508.  
  3509.     BEGIN
  3510.     validateResult := INHERITED Validate;
  3511.     IF (validateResult = kValidValue) & (fTEView <> NIL) & (GetHandleSize(fTEView.fText) >
  3512.        fMaxChars) THEN
  3513.         validateResult := kTooManyCharacters;
  3514.     Validate := validateResult;
  3515.     END;
  3516.  
  3517. {--------------------------------------------------------------------------------------------------}
  3518. {$S DlgOpen}
  3519.  
  3520. PROCEDURE TNumberText.INumberText(itsSuperView: TView;
  3521.                                   itsLocation, itsSize: VPoint;
  3522.                                   itsValue, itsMinimum, itsMaximum: LONGINT);
  3523.  
  3524.     VAR
  3525.         aString:            Str255;
  3526.  
  3527.     BEGIN
  3528.     IEditText(itsSuperView, itsLocation, itsSize, 255);
  3529.     {$IFC qDebug}
  3530.     IF itsMinimum > itsMaximum THEN
  3531.         WRITELN('Minimum value specified is greater than maximum for TNumberText.');
  3532.     {$ENDC}
  3533.     fMinimum := itsMinimum;
  3534.     fMaximum := itsMaximum;
  3535.     NumToString(itsValue, aString);
  3536.     SetText(aString, kDontRedraw);
  3537.     END;
  3538.  
  3539. {--------------------------------------------------------------------------------------------------}
  3540. {$S DlgOpen}
  3541.  
  3542. PROCEDURE TNumberText.IRes(itsDocument: TDocument;
  3543.                            itsSuperView: TView;
  3544.                            VAR itsParams: Ptr); OVERRIDE;
  3545.  
  3546.     VAR
  3547.         aString:            Str255;
  3548.  
  3549.     BEGIN
  3550.     INHERITED IRes(NIL, itsSuperView, itsParams);
  3551.  
  3552.     WITH NumberTextTemplatePtr(itsParams)^ DO
  3553.         BEGIN
  3554.         NumToString(value, aString);
  3555.         SetText(aString, kDontRedraw);
  3556.         {$IFC qDebug}
  3557.         IF minimum > maximum THEN
  3558.             WRITELN('Minimum value specified is greater than maximum for TNumberText.');
  3559.         {$ENDC}
  3560.         fMinimum := minimum;
  3561.         fMaximum := maximum;
  3562.         END;
  3563.  
  3564.     OffsetPtr(itsParams, SIZEOF(NumberTextTemplate));
  3565.     END;
  3566.  
  3567. {--------------------------------------------------------------------------------------------------}
  3568. {$S MAWriteRes}
  3569.  
  3570. PROCEDURE TNumberText.WRes(theResource: ViewRsrcHndl;
  3571.                            VAR itsParams: Ptr); OVERRIDE;
  3572.  
  3573.     VAR
  3574.         nmPtr:                NumberTextTemplatePtr;
  3575.  
  3576.     BEGIN
  3577.     INHERITED WRes(theResource, itsParams);
  3578.  
  3579.     nmPtr := NumberTextTemplatePtr(ExpandPtr(theResource, itsParams, SIZEOF(NumberTextTemplate)));
  3580.  
  3581.     WITH nmPtr^ DO
  3582.         BEGIN
  3583.         value := GetValue;
  3584.         minimum := fMinimum;
  3585.         maximum := fMaximum;
  3586.         END;
  3587.     END;
  3588.  
  3589. {--------------------------------------------------------------------------------------------------}
  3590. {$S MAWriteRes}
  3591.  
  3592. PROCEDURE TNumberText.WriteRes(theResource: ViewRsrcHndl;
  3593.                                VAR itsParams: Ptr); OVERRIDE;
  3594.  
  3595.     BEGIN
  3596.     gWResSignature := 'nmbr'; gWResType := 'TNumberText';
  3597.     WRes(theResource, itsParams);
  3598.     END;
  3599.  
  3600. {--------------------------------------------------------------------------------------------------}
  3601. {$S DlgRes}
  3602.  
  3603. FUNCTION TNumberText.GetValue: LONGINT;
  3604.  
  3605.     VAR
  3606.         aString:            Str255;
  3607.         theValue:            LONGINT;
  3608.  
  3609.     BEGIN
  3610.     GetText(aString);
  3611.     StringToNum(aString, theValue);
  3612.     GetValue := theValue;
  3613.     END;
  3614.  
  3615. {--------------------------------------------------------------------------------------------------}
  3616. {$S DlgNonRes}
  3617.  
  3618. PROCEDURE TNumberText.SetValue(newValue: LONGINT;
  3619.                                redraw: BOOLEAN);
  3620.  
  3621.     VAR
  3622.         aString:            Str255;
  3623.  
  3624.     BEGIN
  3625.     newValue := Max(fMinimum, MIN(fMaximum, newValue));
  3626.     NumToString(newValue, aString);
  3627.     SetText(aString, redraw);
  3628.     END;
  3629.  
  3630. {--------------------------------------------------------------------------------------------------}
  3631. {$S DlgNonRes}
  3632.  
  3633. FUNCTION TNumberText.Validate: LONGINT; OVERRIDE;
  3634.  
  3635.     VAR
  3636.         theString:            Str255;
  3637.         decRec:             Decimal;
  3638.         extValue:            Extended;
  3639.         index:                INTEGER;
  3640.         validPrefix:        BOOLEAN;
  3641.  
  3642.     BEGIN
  3643.     Validate := kValidValue;
  3644.  
  3645.     {!!! This really begs for a fRequired field to test when the string is left empty }
  3646.     { Then we would inform the user that an empty string is not a valid option. }
  3647.     { Also a fDefault field is necessary. GetValue would return fDefault rather }
  3648.     { than 0 when the string is empty.    For now (2.0) we will not validate an empty
  3649.     { string and assume that if the user wants a value they will override. }
  3650.  
  3651.     GetText(theString);
  3652.     IF theString <> '' THEN
  3653.         BEGIN
  3654.         index := 1;
  3655.         Str2Dec(theString, index, decRec, validPrefix);
  3656.         IF validPrefix & (index > Length(theString)) & (decRec.exp >= 0) THEN
  3657.             BEGIN
  3658.             extValue := Dec2Num(decRec);
  3659.             IF extValue < fMinimum THEN
  3660.                 Validate := kValueTooSmall
  3661.             ELSE IF extValue > fMaximum THEN
  3662.                 Validate := kValueTooLarge;
  3663.             END
  3664.         ELSE
  3665.             Validate := kNonNumericCharacters;
  3666.         END;
  3667.     END;
  3668.  
  3669. {--------------------------------------------------------------------------------------------------}
  3670. {$S DlgFields}
  3671.  
  3672. PROCEDURE TNumberText.Fields(PROCEDURE DoToField(fieldName: Str255;
  3673.                                                  fieldAddr: Ptr;
  3674.                                                  fieldType: INTEGER)); OVERRIDE;
  3675.  
  3676.     BEGIN
  3677.     DoToField('TNumberText', NIL, bClass);
  3678.     DoToField('fMinimum', @fMinimum, bLongInt);
  3679.     DoToField('fMaximum', @fMaximum, bLongInt);
  3680.  
  3681.     INHERITED Fields(DoToField);
  3682.     END;
  3683.